testing - 使用 gradle 测试时未找到给定的测试包括

标签 testing groovy gradle

以下是我的代码:

package ro

import org.junit.Test

/**
 * Created by roroco on 3/18/15.
 */
class TryTest extends GroovyTestCase {

    @Test
    def testSmth() {
        assert 1 == 1
    }

}

然后我用'gradle test --tests ro.TryTest'运行它,它引发:

ro.TryTest > junit.framework.TestSuite$1.warning FAILED
    junit.framework.AssertionFailedError at TestSuite.java:97

1 test completed, 1 failed
:test FAILED

这里是 source

最佳答案

GroovyTestCase 的测试需要返回 void,因此您的测试类应该是:

package ro

/**
 * Created by roroco on 3/18/15.
 */
class TryTest extends GroovyTestCase {
    void testSmth() {
        assert 1 == 1
    }
}

此外,您的 build.gradle 文件不需要 javagroovy 插件,groovy 导入 java 根据定义,您的文件可以是:

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.1'
    testCompile 'junit:junit:4.12'
}

顺便说一句,最近我倾向于使用 Spock 代替 GroovyTestCase,所以如果您添加:

testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'

对于您的依赖项,您可以编写 Spock 测试(这将在 src/test/groovy/ro/TrySpec.groovy 中进行)

package ro

class TrySpec extends spock.lang.Specification {
    def 'a simple test'() {
        when: 'I have a number'
            def number = 1

        then: 'It should equal 1'
            number == 1
    }
}

关于testing - 使用 gradle 测试时未找到给定的测试包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29119651/

相关文章:

testing - 如何配置gradle以输出执行的测试总数?

testing - 查看/分析/过滤大量痕迹/日志文件的最佳方式是什么?

ios - 使用 TeSTFlight 进行测试时,应用程序在闪屏后崩溃

testing - 如何在 Testrun 期间获取 WebDriver 版本?

groovy - Groovy 类中的 static {} 有什么意义?

Spring 启动 :Different configurations for running locally vs deployed Jar?

java - Windows 中的 Docker : Failed to load native library 'libnative-platform.so' for Linux amd64

css - 如何测试指针事件 : none with Protractor and Jasmine?

gradle - 使用 Gradle 的 Kotlin 脚本配置获取属性的正确方法

java - 如何在 Groovy 中模拟 String.equals?