views:

970

answers:

3

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?

+4  A: 

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

yawmark
hi and thanks for the reply, I'd seen this link already but I'm still unsure how to get the grails test-app script to run my tests under JUnit 4.
Robin
hi, i've just replace junit4 jar into Grails 1.0.4 lib. I've found it's working as same as junit3, and I cannot let junit4 feature working there.
chanwit
The question was about using JUnit 4 in Grails, but that page is about Groovy
Don
A: 

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.

piepera
This almost worked, except then I started getting build errors because JUnit 3.x classes were no longer available (indirectly referenced from some .class file).
Ed Brannin
I'm not experiencing the same behavior. Which jars reference JUnit 3.x-specific classes?
piepera
+1  A: 

Starting with Grails 1.3M1, JUnit 4 is onboard: http://www.grails.org/1.3-M1+Release+Notes

Stefan