Grails Unit Test Exception java.lang.Exception: No tests found.

I am just starting to learn Grails testing, and I tried to write my first grails test. To do this, I created a new grails project and created a controller named com.rahulserver.SomeController:

package com.rahulserver class SomeController { def index() { } def someAction(){ } } 

When I created this controller, grails automatically created com.rahulserver.SomeControllerSpec in the test / unit folder. Here is my SomeControllerSpec.groovy:

 package com.rahulserver import grails.test.mixin.TestFor import spock.lang.Specification /** * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions */ @TestFor(SomeController) class SomeControllerSpec extends Specification { def setup() { } def cleanup() { } void testSomeAction() { assert 1==1 } } 

When I right-click this class and run this test, I get the following:

 Testing started at 5:21 PM ... |Loading Grails 2.4.3 |Configuring classpath . |Environment set to test .................................... |Running without daemon... .......................................... |Compiling 1 source files . |Running 1 unit test...|Running 1 unit test... 1 of 1 --Output from initializationError-- Failure: | initializationError(org.junit.runner.manipulation.Filter) | java.lang.Exception: No tests found matching grails test target pattern filter from org.junit.runner.Request$1@1f0f9da5 at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35) at org.junit.runner.JUnitCore.run(JUnitCore.java:138) No tests found matching grails test target pattern filter from org.junit.runner.Request$1@1f0f9da5 java.lang.Exception: No tests found matching grails test target pattern filter from org.junit.runner.Request$1@1f0f9da5 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 .Tests FAILED | - view reports in D:\115Labs\grailsunittestdemo\target\test-reports Error | Forked Grails VM exited with error Process finished with exit code 1 

So why does he fail?

EDIT

I am using grails 2.4.3

+5
source share
1 answer

Unit tests are defined using Spock by default:

 void testSomeAction() { assert 1==1 } 

Must be written as:

 void "Test some action"() { expect: 1==1 } 

See http://spockframework.imtqy.com/spock/docs/1.0/index.html

+15
source

All Articles