public class EFCTestSuite extends TestSuite {
private static final String TEST_ROOT = "src/test/";
@SuppressWarnings("unchecked")
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite();
GroovyTestSuite gsuite = new GroovyTestSuite();
// add here all tests
suite.addTestSuite(gsuite.compile(TEST_ROOT + "TestTest.groovy"));
return suite;
}
}
My tests should be groovy JUnit 4 annotated test
class TestTest {
@Test
void additionIsWorking() {
assertEquals 4, 2+2
}
}
But the eclipse junit 4 runner says, he can't find any test ;-(
Changing the class to extend GroovyTestCase
class TestTest extends GroovyTestCase {
void testSomething() {
assert 2 + 2 == 4 : "We're in trouble, arithmetic is broken"
}
}
All works fine. Annotations seems not supported? Is this a
GroovyTestSuite feature or a Eclipse Plugin feature or a Groovy feature?
Or do I something wrong?
Thanks for the help,
Marcel
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
roshandawrani wrote:
>
> As far as I understand, the cause for the problem you are facing is that
> you
> are mixing JUnit 3.x and 4.x ways of defining test suite and writing
> tests.
>
> If you follow the suite.addTestSuite(<someClass>) approach, you are using
> junit 3.x approach of creating test suite. When JUnit looks for tests in
> addTestSuite() path, it does so using 3.x notations (checks whether test
> class extends TestCase and method name/signature meet the requirements,
> etc). In your case TestTest.groovy is defined using 4.x notation - it is a
> POJO, does not follow naming conventions, etc and hence JUnit cannot find
> any tests in it.
>
>
>
Unfortunately I didn’t manage the test Junit test of Groovy Scripts neither
with Junit3 nor 4. Below is my example – with Junit 3 I get “No tests found”
with Junit 4 “Test class can only have one constructor”.
Can someone correct / complete the examples?
Thanks,
Jaromir D.B. Nemec
Tested script
// GroovyOK.groovy
assert 1==1
Junit 3
// Test Groovy Script with JUnit
// RunAllScriptsTests.groovy
//
import groovy.util.GroovyTestSuite
import junit.framework.Test
import junit.textui.TestRunner
class AllTests {
static Test suite() {
def allTests = new GroovyTestSuite()
allTests.addTestSuite(allTests.compile("GroovyOK.groovy"))
return allTests
}
}
TestRunner.run(AllTests.suite())
Gives
.F
Time: 0,015
There was 1 failure:
1) warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError:
No tests found in GroovyOK
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at RunAllScriptsTests.run(RunAllScriptsTests.groovy:18)
at
groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256)
at groovy.lang.GroovyShell.run(GroovyShell.java:218)
at groovy.lang.GroovyShell.run(GroovyShell.java:147)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:493)
at groovy.ui.GroovyMain.run(GroovyMain.java:308)
at groovy.ui.GroovyMain.process(GroovyMain.java:294)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:111)
at groovy.ui.GroovyMain.main(GroovyMain.java:92)
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.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
at
org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
FAILURES!!!
Tests run: 1, Failures: 1, Errors: 0
JUNIT 4
// Test with JUnit4.4 (requires junit-4.8.1.jar)
// RunAllScriptsTestsJU4.groovy
// problem: Test class can only have one constructor
import groovy.util.GroovyTestSuite
import junit.framework.Test
import junit.framework.JUnit4TestAdapter
import junit.textui.TestRunner
class AllTests {
static Test suite() {
def allTests = new GroovyTestSuite()
return new JUnit4TestAdapter(allTests.compile("GroovyOK.groovy"))
}
}
TestRunner.run(AllTests.suite())
Gives
.E
Time: 0,016
There was 1 error:
1) initializationError(GroovyOK)java.lang.IllegalArgumentException: Test
class can only have one constructor
at org.junit.runners.model.TestClass.<init>(TestClass.java:34)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:65)
at
org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:59)
at
org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at
org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at
org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at
junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
at
junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at
org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:107)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:192)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:200)
at AllTests.suite(RunAllScriptsTestsJU4.groovy:14)
at AllTests$suite.call(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
at RunAllScriptsTestsJU4.run(RunAllScriptsTestsJU4.groovy:19)
at
groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256)
at groovy.lang.GroovyShell.run(GroovyShell.java:218)
at groovy.lang.GroovyShell.run(GroovyShell.java:147)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:493)
at groovy.ui.GroovyMain.run(GroovyMain.java:308)
at groovy.ui.GroovyMain.process(GroovyMain.java:294)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:111)
at groovy.ui.GroovyMain.main(GroovyMain.java:92)
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.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
at
org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1
--
View this message in context: http://old.nabble.com/GroovyTestSuite-compile-doesn%27t-support-annotated-Junit-4-test--tp23243411p27026935.html
Sent from the groovy - user mailing list archive at Nabble.com.