Właśnie zaczynam uczyć się testowania Grails i próbowałem napisać mój pierwszy test Grails. W tym celu stworzyłem projekt świeżych grails i stworzył kontroler o nazwie com.rahulserver.SomeController:Wyjątek testu jednostki Grails java.lang.Exception: Nie znaleziono testów pasujących do testowego filtra wzorca gryils
package com.rahulserver
class SomeController {
def index() { }
def someAction(){
}
}
Kiedy stworzyłem ten kontroler, Grails automatycznie stworzył com.rahulserver.SomeControllerSpec w folderze test/jednostkowej. Oto moja 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
}
}
Kiedy kliknij prawym przyciskiem myszy tę klasę i uruchomić ten test, mam następujące:
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 [email protected]
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 [email protected]
java.lang.Exception: No tests found matching grails test target pattern filter from [email protected]
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
Więc dlaczego jest to w przypadku braku?
EDIT
Używam Grails 2.4.3
Dowolny sposób użycia formatu assert? – rahulserver
@rahulserver nadal możesz używać assert, ale nazwij swoją metodę tak, jak pokazuje powyższa odpowiedź. Ale w ten sposób Spock sprawia, że testy są bardziej czytelne i zalecane. – Stealth
Przeczytaj w dokumentacji https://code.google.com/p/spock/wiki/SpockBasics, że "Metoda cech musi zawierać co najmniej jeden wyraźny (tj. Oznaczony) blok" – rahulserver