使用 gradle 测试时未找到给定包含的测试
No tests found for given includes when using gradle test
以下是我的代码:
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.warning FAILED
junit.framework.AssertionFailedError at TestSuite.java:97
1 test completed, 1 failed
:test FAILED
这里是source
测试需要 return void
for GroovyTestCase
,所以你的测试 class 应该是:
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
}
}
以下是我的代码:
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.warning FAILED
junit.framework.AssertionFailedError at TestSuite.java:97
1 test completed, 1 failed
:test FAILED
这里是source
测试需要 return void
for GroovyTestCase
,所以你的测试 class 应该是:
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
}
}