File: migrating.html

package info (click to toggle)
testng 5.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,308 kB
  • ctags: 11,519
  • sloc: java: 48,416; xml: 3,234; makefile: 54; sh: 13
file content (100 lines) | stat: -rw-r--r-- 4,151 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<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>

        <script type="text/javascript" src="http://beust.com/scripts/shCore.js"></script>
        <script type="text/javascript" src="http://beust.com/scripts/shBrushJava.js"></script>
        <script type="text/javascript" src="http://beust.com/scripts/shBrushXml.js"></script>
        <script type="text/javascript" src="http://beust.com/scripts/shBrushBash.js"></script>
        <script type="text/javascript" src="http://beust.com/scripts/shBrushPlain.js"></script>
        <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shCore.css"/>
        <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shThemeCedric.css"/>
        <script type="text/javascript">
          SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
          SyntaxHighlighter.defaults['gutter'] = false;
          SyntaxHighlighter.all();
        </script>

      </head>
<body onLoad="prettyPrint()">

<script type="text/javascript">
    displayMenu("migrating.html")
</script>


<h2 align="center">Migrating from JUnit</h2>

<h3>Using JUnitConverter</h3>
<p>You can easily convert your JUnit tests with <tt>org.testng.JUnitConverter,</tt>&nbsp; 
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>
&nbsp;</li><li><tt>-srcdir | -source &lt;fileName&gt;</tt> (required)<br>
	<tt>-srcdir</tt>, the directory 
	will be recursively traversed and any file that ends in .java will be 
	processed.&nbsp; If you specify <tt>-source</tt>, only that specific Java 
	file will be processed.<br>
&nbsp;</li><li><tt>-d | -overwrite</tt> (mandatory)<br>
	By default, <tt>JUnitConverter </tt>will modify the sources it finds.&nbsp; 
	If you specify a directory with this option, this is where the modified 
	files will be created.&nbsp; If you specify <tt>-overwrite</tt>, the source 
	files will be directly modified.<br>
&nbsp;</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>

<pre class="brush: text">
java org.testng.JUnitConverter -overwrite -annotation -srcdir src
</pre>
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>
&nbsp;</i></li>
		<li><i><tt>JUnitConverter</tt> 
only runs with the JDK5, so if you receive an error (such as &quot;unknown -quiet 
parameter&quot;), 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="brush: xml">
&lt;project name="test" default="init"&gt;
  &lt;target name="init"&gt;
    &lt;taskdef resource="testngtasks" /&gt;
  &lt;/target&gt;
     
  &lt;target name="junitconvert" depends="init"&gt;
    &lt;junit-converter sourcedir="C:\dev\projects\test\java" outputdir="C:\dev\projects\temp" annotations="false" /&gt;
  &lt;/target&gt;
&lt;/project&gt;
</pre>

<h3>Asserts</h3>
Note that the class <tt>org.testng.Assert</tt> 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:

<pre class="brush: java">
import static org.testng.AssertJUnit.*;
</pre>
	

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-238215-2";
urchinTracker();
</script>


</body>