| <html> |
| <head> |
| <title>TestNG - Migrating from JUnit</title> |
| |
| <link rel="stylesheet" href="testng.css" type="text/css" /> |
| <link type="text/css" rel="stylesheet" href="http://beust.com/beust.css" /> |
| <script type="text/javascript" src="http://beust.com/prettify.js"></script> |
| <script type="text/javascript" src="banner.js"></script> |
| </head> |
| <body onLoad="prettyPrint()"> |
| |
| <script type="text/javascript"> |
| displayMenu("migrating.html") |
| </script> |
| |
| |
| <h2 align="center">Migrating from JUnit</h2> |
| <p>You can easily convert your JUnit tests with <tt>org.testng.JUnitConverter,</tt> |
| which you can invoke as follows:</p><ul> |
| <li><tt>-annotation | -javadoc</tt> (required)<br> |
| If <tt>-annotation</tt>, <tt> |
| JUnitConverter</tt> will insert JDK5 annotations, and if you specify <tt>-javadoc</tt>, |
| the tool will insert JavaDoc annotations.<br> |
| </li><li><tt>-srcdir | -source <fileName></tt> (required)<br> |
| <tt>-srcdir</tt>, the directory |
| will be recursively traversed and any file that ends in .java will be |
| processed. If you specify <tt>-source</tt>, only that specific Java |
| file will be processed.<br> |
| </li><li><tt>-d | -overwrite</tt> (mandatory)<br> |
| By default, <tt>JUnitConverter </tt>will modify the sources it finds. |
| If you specify a directory with this option, this is where the modified |
| files will be created. If you specify <tt>-overwrite</tt>, the source |
| files will be directly modified.<br> |
| </li><li><tt>-quiet</tt><br> |
| <tt>JUnitConverter</tt> will not print anything on the console.</li></ul><p>Here is a sample use that will convert all the JUnit tests in the <tt>src/</tt> |
| directory to TestNG:</p> |
| |
| <blockquote class="code"> |
| java org.testng.JUnitConverter -overwrite -annotation -srcdir src |
| </blockquote> |
| Notes:<blockquote> |
| <ul> |
| <li><i><tt>JUnitConverter</tt> uses classes from <tt>tools.jar</tt>, which is located in |
| <tt>$JAVA_HOME/lib/tools.jar</tt>, |
| so make sure you have this jar file in your classpath.<br> |
| </i></li> |
| <li><i><tt>JUnitConverter</tt> |
| only runs with the JDK5, so if you receive an error (such as "unknown -quiet |
| parameter"), make sure your classpath only contains JDK5 jar files.</i></li> |
| </ul> |
| </blockquote><p><tt>JUnitConverter</tt> also has an ant task, which you can invoke as follows: </p> |
| |
| <pre class="prettyprint"> |
| <project name="test" default="init"> |
| <target name="init"> |
| <taskdef resource="testngtasks" /> |
| </target> |
| |
| <target name="junitconvert" depends="init"> |
| <junit-converter sourcedir="C:\dev\projects\test\java" outputdir="C:\dev\projects\temp" annotations="false" /> |
| </target> |
| </project> |
| </pre> |