using JUnit 4 with Ant Topic: JUnit
Trevor John Thompson, Mar 26, 2006 [replies:6]
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?
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

 |
Re: using JUnit 4 with Ant Topic: JUnit
Jan Matèrne PREMIUM, Mar 28, 2006 [replies:4]
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.
Is this item
helpful? yes no
Previous votes Yes: 2 No: 0
|
|
|
 |
 |
Re[2]: using JUnit 4 with Ant Topic: JUnit
srikant lakhanpal, May 11, 2006 [replies:3]
>>"At the moment there is initial support of JUnit4 in the head of Ant's subversion repository."
What does it mean - where I can get some support for running report for Junit 4.0 with junitreport?
Can u specify the link from which I can dowload the intermediate bineries of Ant, supporting junit4.x
plz reply
SRIL
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|
|
 |
 |
 |
 |
Re[4]: using JUnit 4 with Ant Topic: JUnit
srikant lakhanpal, May 11, 2006 [replies:1]
junit report is not listing names of test methods instead of it is printing unkown for Tests written with JUnit4.0(using annotation)
Name Status Type Time(s)
Unknown Success 0.016
unknown Success 0.000
unknown Success 0.000
unknown Success 0.000
If I am extending my classes with TestCase (3.8.1 style) then it is working fine. Can anybody give idea? I am using ANT 1.6.5
can you provide me a sample to resolve my problem. Its very urgents.
Thx.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|
|
 |
Re: using JUnit 4 with Ant Topic: JUnit
michele michele, Jun 15, 2006
I tried to use junit4.1 with ant 1.6.5 and it works!
Here follows my build.xml ant file:
<target name="test" depends="deploy-test">
<junit printsummary="yes" fork="true" haltonfailure="yes">
<classpath>
<pathelement location="${dist}" />
<fileset dir="${dist}" includes="*.jar" />
</classpath>
<formatter type="xml" />
<batchtest haltonfailure="no" todir="${test.reports}">
<fileset dir="${test.java}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
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.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 1
|
|
|
|
|
 |
|