using JUnit 4 with Ant
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Sunday, March 26, 2006 03:40 PM

I am using JUnit 4.0, and having great difficulty getting my tests to run from Ant 1.6.5. I guessed that the junit runner in the Ant distribution is geared to JUnit 3.x, and finally discovered through trial and error that the only way to let my tests be found was by by declaring inport org.junit.Test; // annotation class public final class MyTestCase extends junit.framework.TestCase { . . . @Test public void testSomething() { . . .} } In other words, extends TestCase is required, in the manner of JUnit 3.x, and the use of the @Test annotation is ineffective (for the Ant junit task). Following the suggestion in junit-4.0/doc/faq/faq.htm    More>>

I am using JUnit 4.0, and having great difficulty getting my tests to run from Ant 1.6.5. I guessed that the junit runner in the Ant distribution is geared to JUnit 3.x, and finally discovered through trial and error that the only way to let my tests be found was by by declaring

			
inport org.junit.Test; // annotation class

public final class MyTestCase extends junit.framework.TestCase {
. . .
@Test public void testSomething() { . . .}
}

In other words, extends TestCase is required, in the manner of JUnit 3.x, and the use of the @Test annotation is ineffective (for the Ant junit task).



Following the suggestion in junit-4.0/doc/faq/faq.htm
			
public static junit.framework.Test suite() {
return new junit.framework.JUnit4TestAdapter(MyTestCase.class);
}

does not have any discernible effect.



If i neglect to extend TestCase , then what i get from Ant is
			
[junit] FAILED
[junit] No tests found in MyTestCase
[junit] junit.framework.AssertionFailedError: No tests found in MyTestCase

The test runs OK from the command line, without extending TestCase .
			
java -classpath ".:junit-4.0.jar" org.junit.runner.JUnitCore MyTestCase
JUnit version 4.0
.
Time: 0

OK (1 test)




What am i not getting about using JUnit 4.0 with Ant?    <<Less

Re: using JUnit 4 with Ant

Posted By:   Anonymous  
Posted On:   Thursday, June 15, 2006 12:29 PM

I tried to use junit4.1 with ant 1.6.5 and it works!

Here follows my build.xml ant file:

















Here follows my JUnit4 test class:

public class TestLogging {

@Test public void aSimpleTestMethod() { ... }

@Before public void setUp() throws Exception { .. }

public static junit.framework.Test suite() {
return new JUnit4TestAdapter(TestLogging.class);
}
}

That's all!

Note that the class TestLogging does not exends any class and the test aSimpleTestMethod() will be executed.





Re: using JUnit 4 with Ant

Posted By:   Anonymous  
Posted On:   Tuesday, March 28, 2006 05:59 AM

JUnit4 was introduced after Ant 1.6.5, so Ant cant know anything new from JUnit4. And because Ant uses its own TestRunner, JUnit´s runners are not a solution here.


At the moment there is initial support of JUnit4 in the head of Ant's subversion repository. Build it for yourself and it should work.


We´re discussing with the JUnit team about the future of the JUnit related tasks. Maybe they move to JUnit and JUnit releases an antlib. But nothing decided yet.

About | Sitemap | Contact