CodeNarc - determine if a class is a Grails integration test - grails

I'd like to write a custom CodeNarc rule that validates some aspects of Grails integration test classes. e.g. Spock integration tests should extend IntegrationSpec; not Specification.
But to do this, I need to filter on integration tests while visiting the classes in the rule, and I don't know how to do that.
One idea was to look at the source file path to see if it's in test/integration, but I don't know if it's possible to get the source path of a file.? Any other ideas?

You can definitely limit rule application based on path (as well as class name). Take a look at the configuring rules CodeNarc page.
In particular, you're probably looking for the applyToClassNames and doNotApplyToClassNames properties or the applyToFileNames and doNotApplyToFileNames properties, which should be available on any of the built-in Rules and any custom rules that extend the provided AbstractRule class.

Related

Is there a Grails 3 profile for creating a batch application?

I'd like to create a batch application that has GORM hooked in, etc. Is there a Grails 3 profile for creating a batch (not web) application? Is there some other pattern for using Grails/GORM in a batch context?
EDIT: None of the profiles with 'grails list-profiles' would seem to apply. I've not had luck searching for how to do this, so maybe no one uses this pattern and uses a simple Gradle build instead.
If you want to use the GORM outside grails, I suggest you check the latest GORM documentation. You can creeate a simple groovy app and receive information from the command line and use the GORM functionality inside of it.

FitNesse: how to add a single test page to multiple test suites

how to add a single test page to multiple test suites?
Please note that I want to get the suite name in SuiteSetUp during the test run. Is this possible in FitNesse?
how to add a single test page to multiple test suites
You simply create a page under your suite and include the test page.
Not sure about the second questions, sounds like you're trying to do dynamic include and that's not possible.
I.e.
!include $mySuite
where $mySuite is defined in SuiteSetUp. At least I couldn't find a solution.
You might want to consider generating the data in the SuiteSetUp and use something like parametrized includes.
Personally I found them to work better with symbols.

Where do I put test resources in Grails (2.4)?

I'm working on a service class that needs to process some sort of data payload. In my automated tests, I'm adding some mock data to check the behavior of the service for different inputs. I need to extract these mock data to several files so I can reuse them for other tests. Where do I put such file in a Grails (2.4) app? By convention, most Java projects have src/test/resources for the purpose, but Grails doesn't seem to consider that.
If you are writing unit tests you can put them under test/unit/resources and if you are writing integration tests you put them under test/integration/resources.

Grails: Using "external configuration" to get a plugin's data source

I'm building a plugin that will contain sharable code and configuration for several applications. One things that I'm trying to share is the data source information. Basically I need the application to not have to define it's own data source and instead use the plugin's data source. The best way that I can think of doing this is to take advantage of the external configuration functionality that's available in Grails (http://grails.org/doc/latest/guide/conf.html#3.4%20Externalized%20Configuration). However, I'm not exactly sure how to do this. All the examples I can find online show you how to do this when using an external file on the file system somewhere. I want to use configuration files from the plugin.
According to the documentation linked to above you can specify a "config script" class to use like this:
grails.config.locations = [com.my.app.MyConfig]
This would probably work, however, I can't find documentation on what a "config script" class actually is and how to create one.
By default, the DataSource file of your plugin will not be used (it's ignored in the package stage) but you can create another file that ends with "DataSource" (eg MyPluginDataSource). This is also true for BootStrap and Config.
You will probably need to leave the application DataSource file empty.

Jenkins - view results in web browser

My Jenkins job runs many tests that create log files. In case of failure, I want to look at the log of the failed test. I'd rather use Jenkins web-server to do it, even have a link in the email it sends me.
Is there any plugin that can do it? Or maybe another way?
You provide few details in your question, so it is impossible to give specific advice. In a general level: this is already possible. When your test framework creates JUnit XML files with test results, the test output can be included between the <failure> and </failure> tags. Usually test frameworks should take care of this automatically, so you are probably not using a test framework and are manually generating the XML files containing test results?
I recommend you adopt some test framework. It is usually well worth the effort.

Resources