lin
2025-08-01 633231e833e21d5b8b1c00cb15aedb62b3b78e8f
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<html>
  <head>
    <title>TestNG - Welcome</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("index.html");
</script>
 
 
<h2 >TestNG</h2>
<h2>Now available</h2>
<p align="center">
<a href="book.html">
<img border="0" src="http://beust.com/pics/book-cover.jpg" />
</a>
</p>
<p align="center">
<a href="book.html">Click for more details.</a>
</p>
 
 
 
<p align="right"><font size="-2"><em>C&eacute;dric Beust (cedric at beust.com)<br>
Current version: 6.9.4<br>
Created:&nbsp;April 27th, 2004<br>
Last Modified:&nbsp; May 9th, 2015</em></font></p>
 
 
<p>TestNG is a testing framework inspired from JUnit and NUnit but introducing
some new functionalities that make it more powerful and easier to use, such as:</p>
<ul>
       <li>Annotations.
       </li>
       <li>Run your tests in arbitrarily big thread pools with various policies available
       (all methods in their own thread, one thread per test class, etc...).
       </li>
       <li>Test that your code is multithread safe.
       </li>
       <li>Flexible test configuration.
       </li>
       <li>Support for data-driven testing (with <tt>@DataProvider</tt>).
       </li>
       <li>Support for parameters.
       </li>
       <li>Powerful execution model (no more <tt>TestSuite</tt>).
       </li>
       <li>Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven,
       etc...).
       </li>
       <li>Embeds BeanShell for further flexibility.
       </li>
       <li>Default JDK functions for runtime and logging (no dependencies).
       </li>
       <li>Dependent methods for application server testing.</li>
</ul>
<p>TestNG is designed to cover all categories of tests:&nbsp; unit, functional,
end-to-end, integration, etc...</p>
<p>I started TestNG out of frustration for some JUnit deficiencies which I have
documented 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>
Reading these entries might give you a better idea of the goal I am trying to
achieve with TestNG.&nbsp; You can also check out a quick
<a href="http://www.beust.com/weblog/archives/000176.html">overview of the main
features</a> and an <a href="http://beust.com/weblog/2004/08/18/using-annotation-inheritance-for-testing/">
article</a> describing a very concrete example where the combined use of several
TestNG's features provides for a very intuitive and maintainable testing design.</p>
<p>Here is a very simple test:</p>
 
<h3 class="sourcetitle">SimpleTest.java</h3>
<pre class="brush: java" >
package example1;
 
import org.testng.annotations.*;
 
public class SimpleTest {
 
 @BeforeClass
 public void setUp() {
   // code that will be invoked when this test is instantiated
 }
 
 @Test(groups = { "fast" })
 public void aFastTest() {
   System.out.println("Fast test");
 }
 
 @Test(groups = { "slow" })
 public void aSlowTest() {
    System.out.println("Slow test");
 }
 
}
</pre>
 
The method <tt>setUp()</tt> will be invoked after the test class has been built and before
any test method is run.&nbsp; In this example, we will be running the group
fast, so <tt>aFastTest()</tt> will be invoked while <tt>aSlowTest()</tt> will be
skipped.<p>
<!-------------------------------------
 
 WRITING A TEST
 
 ------------------------------------>
 
Things to note:</p><ul>
       <li>No need to extend a class or implement an interface.</li><li>Even though the example above uses the JUnit conventions, our methods
       can be called any name you like, it's the annotations that tell TestNG what
       they are.</li><li>A test method can belong to one or several groups.</li></ul>
 
       <p>
 
Once you have compiled your test class into the <tt>build</tt> directory, you
can invoke your test with the command line, an ant task (shown below) or an XML
file:
 
<h3 class="sourcetitle">build.xml</h3>
<pre class="brush:java">
&lt;project default="test"&gt;
 
 &lt;path id="cp"&gt;
   &lt;pathelement location="lib/testng-testng-5.13.1.jar"/&gt;
   &lt;pathelement location="build"/&gt;
 &lt;/path&gt;
 
 &lt;taskdef name="testng" classpathref="cp"
          classname="org.testng.TestNGAntTask" /&gt;
 
 &lt;target name="test"&gt;
   &lt;testng classpathref="cp" groups="fast"&gt;
     &lt;classfileset dir="build" includes="example1/*.class"/&gt;
   &lt;/testng&gt;
 &lt;/target&gt;
 
&lt;/project&gt;
</pre>
 
Use ant to invoke it:
 
<pre class="brush: text">
c:&gt; ant
Buildfile: build.xml
 
test:
[testng] Fast test
[testng] ===============================================
[testng] Suite for Command line test
[testng] Total tests run: 1, Failures: 0, Skips: 0
[testng] ===============================================
 
 
BUILD SUCCESSFUL
Total time: 4 seconds
</pre>
 
Then you can browse the result of your tests:
 
<pre class="brush: text">
start test-output\index.html (on Windows)
</pre>
 
<h3><a name="requirements">Requirements</a></h3>
<p>TestNG requires JDK 7 or higher.</p>
 
<h3><a name="mailing-lists">Mailing-lists</a></h3>
 
<ul>
<li>The users mailing-list can be found on <a href="http://groups.google.com/group/testng-users">Google Groups</a>.
<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>.
<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>.
</ul>
 
 
<h3><a name="locations-projects">Locations of the projects</a></h3>
<p>If you are interested in contributing to TestNG or one of the IDE plug-ins,
you will find them in the following locations:</p>
<ul>
       <li><a href="http://github.com/cbeust/testng/">TestNG</a></li>
       <li><a href="http://github.com/cbeust/testng-eclipse/">Eclipse plug-in</a></li>
<!--
       <li><a href="http://code.google.com/p/testng/">TestNG</a></li>
       <li><a href="http://code.google.com/p/testng-eclipse">Eclipse plug-in</a></li>
-->
      <li><a href="https://github.com/JetBrains/intellij-community/tree/master/plugins/testng">IDEA IntelliJ plug-in</a></li>
       <li><a href="http://wiki.netbeans.org/TestNG">NetBeans plug-in</a></li>
</ul>
<h3><a id="bug-reports" name="bug-reports">Bug reports</a></h3>
 
If you think you found a bug, here is how to report it:
 
<ul>
<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...).
 
<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.
 
<li><a href="https://github.com/cbeust/testng/issues">File a bug</a>.
 
</ul>
 
</p>
 
<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>
 
<h3>License</h3>
 
<a href="http://testng.org/license">Apache 2.0</a>
 
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-238215-2";
urchinTracker();
</script>
 
 
</body>
 
</html>