以下是我的代码:
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 文件不需要 java
和 groovy
插件,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/