Reputation: 2616
I'd like to use some JUnit 4 functionality in my grails testing, but currently grails tests run under JUnit 3. JUnit 4 can be used from groovy but replacing the JUnit jar within grails with a JUnit 4 one doesn't seem to enable the functionality I'm looking for.
Anyone know how I can get grails to run my tests with junit 4?
Upvotes: 3
Views: 5256
Reputation: 1944
You can use JUnit 4 with Grails as long as you're using Groovy 1.5+ and Java 5+:
http://groovy.codehaus.org/Using+JUnit+4+with+Groovy
Upvotes: 4
Reputation: 141
As of Grails 1.3.6, it looks like Junit 4 is supported incompletely. Integration tests are fine in Junit 4, but unit tests that extend GrailsUnitTestCase are limited to Junit 3. GrailsUnitTestCase extends GroovyTestCase which is still tied to Junit 3.
In the Groovy doc (http://groovy.codehaus.org/Using+JUnit+4+with+Groovy) it says that Junit 4 is supported, but notice the statement "Currently, there are no special Groovy extensions for JUnit 4". So you can use it, but none of the Groovy test extensions take advantage of it.
This is a killer for unit tests that need to use any of the Grails test extensions like mockDomain. I'm proceeding on the assumption that I'm effectively stuck with Junit 3.
Upvotes: 4
Reputation: 39925
Starting with Grails 1.3M1, JUnit 4 is onboard: http://www.grails.org/1.3-M1+Release+Notes
Upvotes: 1
Reputation: 2123
Grails does not support JUnit 4. They're looking into supporting it in Grails 1.3. You can force a dependency on JUnit 4, but the Grails tools might ignore your tests, run them incorrectly, or you might see other weird side effects.
To force a JUnit 4 dependency (at your own risk), open your grails-app/conf/BuildConfig.groovy file. In that file, modify the dependencies and inherits sections to include the following:
inherits("globals") {
excludes "junit"
}
dependencies {
test "junit:junit:4.7"
}
Then, in SpringSource Tool Suite, right-click your project and select Grails Tools -> Refresh Dependencies. This should replace junit 3.8.1 in your Grails Dependencies with junit 4.7.
Upvotes: 0