My goal is to write test for my own Grails plugin. steps taken so far:
- Step - Create separate grails app (in our case, testApp) inside the Grails Plugin 'test' folder
Step - Make the plugin to be inline for the application - testApp by adding following Line in BuildConfig.groovy
grails.plugin.location.PluginName = '../../../../PluginName'
The issue is that in the Unit test, the Service (from the inline plugin) are not injected like it is for regular app in Unit Test. Here is sample test:
@TestFor(SampleService)
class SampleServiceUnitSpec extends UnitSpec {
def "Sample Test"(){
setup:
def test = 'ok'
when:
test = "changed"
then:
assert service
assert "changed" == test
}
}
The service is injected if this test is run from grails app and service is part of the app. The service is not injected if this test is run from the testApp with inline plugin containing the service. The service is not injected if the test is plugin unit test and the service declared in the plugin.
How to inject service so it can be tested? Any good docs,posts.etc on how best test Grails plugins? Thank You