Unit tests not starting in simple Grails project
Just some background before I start. I'm an experienced Java developer, with a decent amount of Groovy experience. I haven't used Grails before, but have used Rails so I'm used to the general mode of development with that sort of tool set. I'm also a long-time IntelliJ IDEA user, so I'm very familiar with the environment.
My environment is OSX 10.8.5 on a Macbook Pro, with Java 1.7.0_45, Groovy 2.2.1, and Grails 2.3.4. Oh, and IntelliJ IDEA 13.0.1.
I'm considering using Grails for a project, so I started working through The Definitive Guide to Grails 2. I fired up IntelliJ IDEA and created a new Grails project and named it gTunes (just following the example in the book). I then clicked on the project and selected New->Grails Controller. I can then successfully run the application and see a basic hello-world message displayed. So far so good!
I can not however get the unit tests to run. When I try to run them (just right-click on the project and select Run All Tests), I get a number of warning messages related to SLF4J bindings and not having log4j configuration, which are no big deal. And then in the console I get the message:
Process finished with exit code 0
Ordinary exit, but the list of tests in the left-hand pane show the tests as pending or running and at the bottom of the Run window there's the message:
Failed to start: 0 passed, 1 not started in 2s
You can see all of this in the screen shot below.
I've messed around with the unit test itself quite a bit but the code looks totally fine. This is NOT a complicated project, so I don't think I've done anything to screw up the unit tests. Everything seems to build fine, it just... doesn't run the test. I've also attached a zip of the project contents, although it's really easy to recreate without that!
And this is almost certainly related, but when I ran grails test-app at the command line, I got the following message:
| java.lang.Exception: No tests found matching grails test target pattern filter from org.junit.runner.Request$1@589c6538
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
| Completed 1 unit test, 1 failed in 0m 0s
So that's looking for tests and not finding them. This is the difference between JUnit and Spock tests, I guess (I'm not familiar at all with Spock). I then copied my StoreControllerSpec test over to StoreControllerTests, changed the code to remove the Spock dependencies, and now I get this with grails test-app:
| Running 2 unit tests...
| Running 2 unit tests... 1 of 2
| Completed 1 unit test, 0 failed in 0m 7s
| Tests PASSED - view reports in /Users/rherrick/Development/WurstWorks/HoneyDo/gTunes/target/test-reports
I'm guessing that "2 unit tests" thing is because the StoreControllerSpec definition is still in there, but just not getting run. I still get exactly the same response when trying to run all of the unit tests in the IDE however. I can right-click on StoreControllerTests and run that and it works, but when I try to run all tests, it only recognizes StoreControllerSpec.
Help to get this resolved would be greatly appreciated!
Attachment(s):
gTunesNoUnitTests.zip
请先登录再写评论。
Hi Rick,
The tests don't work because it's not in the Spock specification format (the test extend from Specification now). You need at least a when: / given: block to have the tests run.
Erik
Automated testing is a key part of Grails. Hence, Grails provides many ways to making testing easier from low level unit testing to high level functional tests. This section details the different capabilities that Grails offers for testing.
tellthebell