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

标签 unit-testing grails groovy

我刚开始学习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/

相关文章:

c++ - 使用 GTest 访问违规读取位置,无需任何复杂测试

c++ - Automake AM_LDADD 解决方法

unit-testing - 将模拟需求语句放在Grails测试中的正确位置是什么?

grails - 种子种子插件的种子文件中如何循环播放?

tomcat - Jenkins 部署到 Tomcat 失败

Java 注释处理器 - 带注释的 Kotlin 类单元测试

python - 在 pycharm/pydev 中调试 pytest 事后异常

spring - 当我添加对其他 bean 的引用时,为什么 Apache CXF 会抛出 IllegalAnnotationsException?

grails - 从.gsp页面打印页面

groovy - + 运算符在 groovy 中的字符串连接中表现出意外