import static org.testng.AssertJUnit.*;
TestNG can automatically recognize and run JUnit tests, so you can use TestNG as a runner for all your existing tests and write new tests using TestNG.
All you have to do is to put JUnit library on the TestNG classpath, so it can find and use JUnit classes, change your test runner from JUnit to TestNG in Ant and then run TestNG in "mixed" mode. This way you can have all your tests in the same project, even in the same package, and start using TestNG. This approach also allows you to convert your existing JUnit tests to TestNG incrementally.
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true"> <batchtest todir="${build.test.results.dir}"> <fileset dir="${test.src.dir}"> <include name="**/*Test.*"/> </batchtest> <classpath> <path path="${run.test.classpath}"/> </classpath> <syspropertyset> <propertyref prefix="test-sys-prop."/> <mapper from="test-sys-prop.*" to="*" type="glob"/> </syspropertyset> <formatter type="xml"/> <jvmarg value="-ea"/> <jvmarg line="${run.jvmargs}"/> </junit>TestNG version:
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}"/> <fileset id="mixed.tests" dir="${test.src.dir}"> <include name="**/*Test.*"/> </fileset> <testng mode="mixed" classfilesetref="mixed.tests" workingDir="${work.dir}" failureProperty="tests.failed" outputdir="${build.test.results.dir}"> <classpath> <pathelement path="${build.test.classes.dir}"/> <pathelement path="${run.test.classpath}"/> <pathelement path="${junit.lib}"/> </classpath> <propertyset> <propertyref prefix="test-sys-prop."/> <mapper from="test-sys-prop.*" to="*" type="glob"/> </propertyset> <jvmarg line="${run.jvmargs}"/> </testng>