1<html>
2  <head>
3    <title>TestNG - Welcome</title>
4      <link rel="stylesheet" href="testng.css" type="text/css" />
5      <link type="text/css" rel="stylesheet" href="http://beust.com/beust.css"  />
6      <script type="text/javascript" src="http://beust.com/prettify.js"></script>
7      <script type="text/javascript" src="banner.js"></script>
8
9      <script type="text/javascript" src="http://beust.com/scripts/shCore.js"></script>
10      <script type="text/javascript" src="http://beust.com/scripts/shBrushJava.js"></script>
11      <script type="text/javascript" src="http://beust.com/scripts/shBrushXml.js"></script>
12      <script type="text/javascript" src="http://beust.com/scripts/shBrushBash.js"></script>
13      <script type="text/javascript" src="http://beust.com/scripts/shBrushPlain.js"></script>
14      <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shCore.css"/>
15      <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shThemeCedric.css"/>
16      <script type="text/javascript">
17        SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
18        SyntaxHighlighter.defaults['gutter'] = false;
19        SyntaxHighlighter.all();
20      </script>
21
22    </head>
23
24<body onload="prettyPrint()">
25
26<script type="text/javascript">
27   displayMenu("index.html");
28</script>
29
30
31<h2 >TestNG</h2>
32<h2>Now available</h2>
33<p align="center">
34<a href="book.html">
35<img border="0" src="http://beust.com/pics/book-cover.jpg" />
36</a>
37</p>
38<p align="center">
39<a href="book.html">Click for more details.</a>
40</p>
41
42
43
44<p align="right"><font size="-2"><em>C&eacute;dric Beust (cedric at beust.com)<br>
45Current version: 6.9.4<br>
46Created:&nbsp;April 27th, 2004<br>
47Last Modified:&nbsp; May 9th, 2015</em></font></p>
48
49
50<p>TestNG is a testing framework inspired from JUnit and NUnit but introducing
51some new functionalities that make it more powerful and easier to use, such as:</p>
52<ul>
53       <li>Annotations.
54       </li>
55       <li>Run your tests in arbitrarily big thread pools with various policies available
56       (all methods in their own thread, one thread per test class, etc...).
57       </li>
58       <li>Test that your code is multithread safe.
59       </li>
60       <li>Flexible test configuration.
61       </li>
62       <li>Support for data-driven testing (with <tt>@DataProvider</tt>).
63       </li>
64       <li>Support for parameters.
65       </li>
66       <li>Powerful execution model (no more <tt>TestSuite</tt>).
67       </li>
68       <li>Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven,
69       etc...).
70       </li>
71       <li>Embeds BeanShell for further flexibility.
72       </li>
73       <li>Default JDK functions for runtime and logging (no dependencies).
74       </li>
75       <li>Dependent methods for application server testing.</li>
76</ul>
77<p>TestNG is designed to cover all categories of tests:&nbsp; unit, functional,
78end-to-end, integration, etc...</p>
79<p>I started TestNG out of frustration for some JUnit deficiencies which I have
80documented on my weblog <a href="http://beust.com/weblog/2004/08/25/testsetup-and-evil-static-methods/">here</a> and <a href="http://beust.com/weblog/2004/02/08/junit-pain/">here</a>
81Reading these entries might give you a better idea of the goal I am trying to
82achieve with TestNG.&nbsp; You can also check out a quick
83<a href="http://www.beust.com/weblog/archives/000176.html">overview of the main
84features</a> and an <a href="http://beust.com/weblog/2004/08/18/using-annotation-inheritance-for-testing/">
85article</a> describing a very concrete example where the combined use of several
86TestNG's features provides for a very intuitive and maintainable testing design.</p>
87<p>Here is a very simple test:</p>
88
89<h3 class="sourcetitle">SimpleTest.java</h3>
90<pre class="brush: java" >
91package example1;
92
93import org.testng.annotations.*;
94
95public class SimpleTest {
96
97 @BeforeClass
98 public void setUp() {
99   // code that will be invoked when this test is instantiated
100 }
101
102 @Test(groups = { "fast" })
103 public void aFastTest() {
104   System.out.println("Fast test");
105 }
106
107 @Test(groups = { "slow" })
108 public void aSlowTest() {
109    System.out.println("Slow test");
110 }
111
112}
113</pre>
114
115The method <tt>setUp()</tt> will be invoked after the test class has been built and before
116any test method is run.&nbsp; In this example, we will be running the group
117fast, so <tt>aFastTest()</tt> will be invoked while <tt>aSlowTest()</tt> will be
118skipped.<p>
119<!-------------------------------------
120
121 WRITING A TEST
122
123 ------------------------------------>
124
125Things to note:</p><ul>
126       <li>No need to extend a class or implement an interface.</li><li>Even though the example above uses the JUnit conventions, our methods
127       can be called any name you like, it's the annotations that tell TestNG what
128       they are.</li><li>A test method can belong to one or several groups.</li></ul>
129
130       <p>
131
132Once you have compiled your test class into the <tt>build</tt> directory, you
133can invoke your test with the command line, an ant task (shown below) or an XML
134file:
135
136<h3 class="sourcetitle">build.xml</h3>
137<pre class="brush:java">
138&lt;project default="test"&gt;
139
140 &lt;path id="cp"&gt;
141   &lt;pathelement location="lib/testng-testng-5.13.1.jar"/&gt;
142   &lt;pathelement location="build"/&gt;
143 &lt;/path&gt;
144
145 &lt;taskdef name="testng" classpathref="cp"
146          classname="org.testng.TestNGAntTask" /&gt;
147
148 &lt;target name="test"&gt;
149   &lt;testng classpathref="cp" groups="fast"&gt;
150     &lt;classfileset dir="build" includes="example1/*.class"/&gt;
151   &lt;/testng&gt;
152 &lt;/target&gt;
153
154&lt;/project&gt;
155</pre>
156
157Use ant to invoke it:
158
159<pre class="brush: text">
160c:&gt; ant
161Buildfile: build.xml
162
163test:
164[testng] Fast test
165[testng] ===============================================
166[testng] Suite for Command line test
167[testng] Total tests run: 1, Failures: 0, Skips: 0
168[testng] ===============================================
169
170
171BUILD SUCCESSFUL
172Total time: 4 seconds
173</pre>
174
175Then you can browse the result of your tests:
176
177<pre class="brush: text">
178start test-output\index.html (on Windows)
179</pre>
180
181<h3><a name="requirements">Requirements</a></h3>
182<p>TestNG requires JDK 7 or higher.</p>
183
184<h3><a name="mailing-lists">Mailing-lists</a></h3>
185
186<ul>
187<li>The users mailing-list can be found on <a href="http://groups.google.com/group/testng-users">Google Groups</a>.
188<li>If you are interested in working on TestNG itself, join the <a href="http://groups.google.com/group/testng-users">developer mailing-list</a>.
189<li>If you are only interested in hearing about new versions of TestNG, you can join the low volume <a href="http://groups.google.com/group/testng-announcements">TestNG announcement mailing-list</a>.
190</ul>
191
192
193<h3><a name="locations-projects">Locations of the projects</a></h3>
194<p>If you are interested in contributing to TestNG or one of the IDE plug-ins,
195you will find them in the following locations:</p>
196<ul>
197       <li><a href="http://github.com/cbeust/testng/">TestNG</a></li>
198       <li><a href="http://github.com/cbeust/testng-eclipse/">Eclipse plug-in</a></li>
199<!--
200       <li><a href="http://code.google.com/p/testng/">TestNG</a></li>
201       <li><a href="http://code.google.com/p/testng-eclipse">Eclipse plug-in</a></li>
202-->
203      <li><a href="https://github.com/JetBrains/intellij-community/tree/master/plugins/testng">IDEA IntelliJ plug-in</a></li>
204       <li><a href="http://wiki.netbeans.org/TestNG">NetBeans plug-in</a></li>
205</ul>
206<h3><a id="bug-reports" name="bug-reports">Bug reports</a></h3>
207
208If you think you found a bug, here is how to report it:
209
210<ul>
211<li>Create a small project that will allow us to reproduce this bug. In most cases, one or two Java source files and a <tt>testng.xml</tt> file should be sufficient. Then you can either zip it and email it to the <a href="http://groups.google.com/group/testng-dev">testng-dev mailing-list</a> or make it available on an open source hosting site, such as <a href="http://github.com">github</a> or <a href="http://code.google.com/hosting/">Google code</a> and email <tt>testng-dev</tt> so we know about it. Please make sure that this project is self contained so that we can build it right away (remove the dependencies on external or proprietary frameworks, etc...).
212
213<li>If the bug you observed is on the Eclipse plug-in, make sure your sample project contains the <tt>.project</tt> and <tt>.classpath</tt> files.
214
215<li><a href="https://github.com/cbeust/testng/issues">File a bug</a>.
216
217</ul>
218
219</p>
220
221<p>For more information, you can either <a href="download.html">download TestNG</a>, read the <a href="documentation-main.html">manual</a> or browse the links at the<a href="#top">top</a>.</p>
222
223<h3>License</h3>
224
225<a href="http://testng.org/license">Apache 2.0</a>
226
227<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
228</script>
229<script type="text/javascript">
230_uacct = "UA-238215-2";
231urchinTracker();
232</script>
233
234
235</body>
236
237</html>
238
239