DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Groovy & Grails
Reload this Page groovy testrunner for Junit4 tests
Notices
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Sep 2010
Default groovy testrunner for Junit4 tests - 09-15-2010, 08:51 PM

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)
	}

}
Reply With Quote
Reply

Tags
groovy, junit4, testrunner

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for Grails/Groovy Contract Programming rossswest Groovy & Grails 0 05-12-2010 12:59 PM
groovy.eclipse usage in RCP application MaxRoux Eclipse 0 02-18-2010 10:06 AM
Java-Groovy integration andyberlin Groovy & Grails 0 06-22-2009 03:55 AM
Eclipse is too slow for editing Groovy code sontrang91 Eclipse 0 09-23-2008 11:55 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com