2015-07-17 30 views
5

Sadece Grails testini öğrenmeye başladım ve ilk not testini yazmaya çalıştım. Bunun için yeni bir değerlendirme projesi oluşturdum ve Bu denetleyici yarattığı zamanGrails Unit Test İstisnası java.lang.Exception: Test sonuç desen süzgeci ile eşleşen test bulunamadı

package com.rahulserver 

class SomeController { 

    def index() { } 
    def someAction(){ 

    } 
} 

, grails otomatik olarak test/birim klasörü altında bir com.rahulserver.SomeControllerSpec oluşturuldu: com.rahulserver.SomeController adında bir denetleyici yarattı.

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 
    } 
} 

Birazdan bu sınıfı tıklatın ve Bu testi, şu olsun:

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 

Peki neden başarısız olduğunun İşte benim SomeControllerSpec.groovy nedir?

DÜZENLEME

kullanıyorum grails 2.4.3

cevap

14

testler varsayılan olarak Spock tanımlanır birimi:

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

void testSomeAction() { 
    assert 1==1 
} 

olarak yazılabilir olmalı

Bkz. http://spockframework.github.io/spock/docs/1.0/index.html

+0

Destek biçimini kullanmanın herhangi bir yolu var mı? – rahulserver

+0

@rahulserver hala savcı kullanabilirsiniz ama yönteminizi yukarıdaki yanıtın gösterdiği gibi adlandırın. Ancak bunu yapmak Spock yolu, testlerinizi daha okunabilir ve tavsiye edilir kılar. – Stealth

+0

https://code.google.com/p/spock/wiki/SpockBasics adresinde bulunan "Bir özellik yönteminin en az bir açık (yani etiketli) bloğa sahip olması gerekir" konusunu okuyun. – rahulserver

İlgili konular