我正在嘗試爲我的Groovy代碼編寫Junit4測試用例。 Junit 4測試用例在我的Eclipse IDE(SpringSource Tool Suite)中正常工作。但是,我無法運行測試運行所有測試用例。Groovy,Junit4單元測試和相關測試運行器
這是我目前在測試跑步者的嘗試。這幾乎是直接取自Groovy的網站本身:
org.codehaus.groovy.runtime.InvokerInvocationException:
org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack:
No signature of method: GSieveTest.main() is applicable for argument types:() values: []
什麼問題:在
import groovy.util.GroovyTestSuite;
import org.codehaus.groovy.runtime.ScriptTestAdapter
import junit.framework.*;
class allTests {
static Test suite() {
def gsuite = new GroovyTestSuite()
gsuite.addTest(new ScriptTestAdapter(gsuite.compile("test/GSieveTest.groovy"), [] as String[]))
return gsuite
}
}
junit.textui.TestRunner.run(allTests.suite())
結果?哦,這是GSieveTest.groovy。我運行正常使用「運行方式JUnit測試...」
import static org.junit.Assert.assertEquals;
import org.junit.Test;
class GSieveTest {
@Test
public void Primes1To10() {
def sieve = (0..10).toList()
GSieve.filter(sieve); // [1,2,3,5,7]
assertEquals("Count of primes in 1..10 not correct", 5, (sieve.findAll {it -> it != 0}).size());
}
@Test
public void FiftyNineIsPrime() {
def sieve = (0..60).toList()
GSieve.filter(sieve);
assertEquals("59 must be a prime", 59, sieve[59]);
}
@Test
public void Primes1To100() {
def sieve = (0..100).toList()
GSieve.filter(sieve);
def list = sieve.findAll {it -> it != 0}
def primes = [1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
println list
println primes
assertEquals(true, list == primes)
}
}
哪裏是測試的代碼,因爲那是什麼失敗? – 2010-09-13 02:31:51
以下是Junit4測試代碼。當「Run as Junit test ...」運行良好時 – rock298 2010-09-13 23:44:09
不應該GSieveTest擴展TestCase和allTests擴展GroovyTestSuite嗎? – 2010-09-14 00:26:04