gpt4 book ai didi

unit-testing - Grails单元测试异常java.lang.Exception : No tests found matching grails test target pattern filter

转载 作者:行者123 更新时间:2023-12-04 04:49:46 27 4
gpt4 key购买 nike

我刚开始学习Grails测试,并尝试编写第一个grails测试,为此,我创建了一个新的grails项目并创建了一个名为com.rahulserver.SomeController的 Controller :

package com.rahulserver

class SomeController {

def index() { }
def someAction(){

}
}

当我创建此 Controller 时,grails自动在test/unit文件夹下创建com.rahulserver.SomeControllerSpec。
这是我的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
}
}

当我右键单击此类并运行此测试时,我得到以下信息:
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

那为什么会失败呢?

编辑

我正在使用grails 2.4.3

最佳答案

默认情况下,单元测试是使用Spock定义的:

void testSomeAction() {
assert 1==1
}

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

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

关于unit-testing - Grails单元测试异常java.lang.Exception : No tests found matching grails test target pattern filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31475317/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com