Running tests in IntelliJ different than running from command-line

I have a Grails project that I've just imported into IntelliJ IDEA.  I just downloaded IDEA so it's v11.1.3.

When I run 'grails test-app' from the command-line, I get two errors and two failures - which I was expecting.  The errors are in fact why I'm trying out IntelliJ IDEA because I need to debug to find out why I'm getting the errors.

When I run all the tests in IntelliJ, I get a totally different set of errors.  I get 9 failures and 4 tests won't even run.

I thought that it might be the Spock test framework that I'm using, so I wrote some "normal" test cases and I get the same errors.

For this normal unit test, I get both of my tests succeeding when run from the command line.  When I run it in IntelliJ, I get one success and one failure.

Here is the test method that fails:

@TestFor(ConformanceController)
class ConformanceControllerTests {
     void testOneConformanceAsXML() {
         def mockConformance = new grails.test.GrailsMock(Conformance)
         mockConformance.demand.static.findById() {id -> mockConformance.createMock()}
         controller.params.id = 1
         request.addHeader "Accept", "application/xml"
         controller.show()
         mockConformance.verify()  //Test 1
         response.contentType.startsWith("application/xml")  //Test 2
         response.text == ...xml text to check against... //Test 3

     }

}

I fail on the Test 2 line because the response.contentType returns null.  When I debug the test, I also see that the response.text is also null.  So it seems like the response that I'm getting back hasn't been filled with what the controller did - via a render(contentType:"application/xml", text:"...xml text...")

So why does my test run fine from the command-line but not run from within IntelliJ?
1 comment
Comment actions Permalink

On my machine your example works fine.
Try to call File -> Invalidate Caches  and rebuild project

0

Please sign in to leave a comment.