【发布时间】:2014-07-06 13:48:28
【问题描述】:
在 groovy 中创建了两个测试,能够将它们作为 groovy 测试用例不雅地运行,但是当我创建一个测试套件并在 cmd 行上像 groovy MyTestSuite.groovy 一样运行它们时,我收到以下错误:
F.F
Time: 0
There were 2 failures:
1) warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError: No tests found in mypack.ArithmeticTest
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1318)
at org.codehaus.groovy.runtime.InvokerHelper.invokeStaticMethod(InvokerHelper.java:927)
at org.codehaus.groovy.runtime.InvokerHelper.invokeStaticMethod(InvokerHelper.java:77)
at groovy.lang.GroovyShell.runJUnit3TestSuite(GroovyShell.java:370)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:277)
at groovy.lang.GroovyShell.run(GroovyShell.java:502)
at groovy.lang.GroovyShell.run(GroovyShell.java:491)
"a.txt" 53L, 3408C
测试套件类如下
package mypack
import junit.framework.TestSuite
import junit.framework.JUnit4TestAdapter
public class myTestSuite extends TestSuite {
// Since Eclipse launches tests relative to the project root,
// declare the relative path to the test scripts for convenience
private static final String TEST_ROOT = "src/mypack/";
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite();
GroovyTestSuite gsuite = new GroovyTestSuite();
suite.addTestSuite(gsuite.compile("/Users/barumugham/Documents/workspace/Groovy/UnitTestGroovy/src/mypack/ArithmeticGroovy.groovy"));
suite.addTestSuite(gsuite.compile("/Users/barumugham/Documents/workspace/Groovy/UnitTestGroovy/src/mypack/ArrayTest.groovy"));
return suite;
}
}
ArithmeticGroovy.groovy
package mypack
import org.junit.Test
import static org.junit.Assert.assertEquals
class ArithmeticTest {
@Test
void additionIsWorking() {
assertEquals 4, 2+2
}
@Test(expected=ArithmeticException)
void divideByZero() {
println 1/0
}
}
当我通过 Eclipse 运行它时,我得到了初始化错误。我是 groovy 的新手,感谢您的帮助
【问题讨论】:
-
尝试重命名测试方法,以test开头。