using junit 4 in grails

前端 未结 4 1024
醉话见心
醉话见心 2021-01-06 16:32

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 w

相关标签:
4条回答
  • 2021-01-06 17:11

    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.

    0 讨论(0)
  • 2021-01-06 17:11

    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

    0 讨论(0)
  • 2021-01-06 17:15

    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.

    0 讨论(0)
  • 2021-01-06 17:16

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

    0 讨论(0)
提交回复
热议问题