## Migrating from JUnit

### Using JUnitConverter

You can easily convert your JUnit tests with `org.testng.JUnitConverter,` which you can invoke as follows:

- `-annotation | -javadoc` (required)
  If `-annotation`, `JUnitConverter` will insert JDK5 annotations, and if you specify `-javadoc`, the tool will insert JavaDoc annotations.
- `-srcdir | -source <fileName>` (required)
  `-srcdir`, the directory will be recursively traversed and any file that ends in .java will be processed. If you specify `-source`, only that specific Java file will be processed.
- `-d | -overwrite` (mandatory)
  By default, `JUnitConverter` 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 `-overwrite`, the source files will be directly modified.
- `-quiet`
  `JUnitConverter` will not print anything on the console.

Here is a sample use that will convert all the JUnit tests in the `src/` directory to TestNG:

    java org.testng.JUnitConverter -overwrite -annotation -srcdir src

Notes:

> - `JUnitConverter` uses classes from `tools.jar`, which is located in `$JAVA_HOME/lib/tools.jar`, so make sure you have this jar file in your classpath.
> - `JUnitConverter` 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.

`JUnitConverter` also has an ant task, which you can invoke as follows:

    <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>

### Asserts

Note that the class `org.testng.Assert` uses a different argument ordering than the ones used by JUnit. If you are porting code that uses JUnit's asserts, you might want to us a static import of that class:

    import static org.testng.AssertJUnit.*;