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