Reputation: 12371
With grails 2.4, when you create a controller for example, it creates a unit test class such as:
@TestFor(SessionService)
class SessionServiceSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "test something"() {
}
}
so you create 20 controllers, and get 20 test classes.
When you try to run grails test-app, it fails with the following error:
java.lang.Exception:
No tests found matching grails test target pattern filter from org.junit.runner.Request
It never gets to run our integration tests.
So tests Grails creates for you do not work out of the box.
We could delete all the created test specs classes, but then we kind of want them there ready for if we want to write them.
It's a shame Grails doesn't tell you which tests or class throws this exception.
Upvotes: 2
Views: 1641
Reputation: 50265
This looks like a weird argument to me. When you create a controller, unit spec is created for it by default based on a template which can be easily tailored according to your need.
does it for you. Now to answer your questions:
Yes there is a way to only run integration tests.
grails test-app integration:
After using install-templates
modify the Controller.groovy
template under src\templates\testing
to something
like:
@artifact.package@import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin}
* for usage instructions
*/
@TestFor(@artifact.testclass@)
class @artifact.name@ extends Specification {
def setup() {
}
def cleanup() {
}
void "test something"() {
expect:
1 == 1
}
}
This will not fail your test when run but it defeats the whole purpose of
writing failing test -> modify code -> fixing test approach
of TDD. I would rather implement a failing test and then write minimal logic in controller to pass the test.
Upvotes: 6