I'm writing groovy test cases in Junit4. The tests run fine in Eclipse w/ "Run as Junit Test". I want a test runner to run all my Junit4 tests at once but cannot get this to work despite following directions on Groovy Home wiki.
Here is the recommended runner:
Code:
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())
Here is the output (in console window):
.E
Time: 0.019
There was 1 error:
1) TestCase for script: GSieveTestorg.codehaus.groovy.runtime.InvokerInvoc ationException: org.codehaus.groovy.runtime.metaclass.MissingMetho dExceptionNoStack: No signature of method: GSieveTest.main() is applicable for argument types: () values: []
Possible solutions: wait(), wait(long), wait(long, int), any(), print(java.lang.Object), find(groovy.lang.Closure)
at org.codehaus.groovy.reflection.CachedMethod.invoke (CachedMethod.java:95)
BTW here is the test class which runs fine as a Junit test.
Code:
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)
}
}