-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtestng_run_modes.html
243 lines (242 loc) · 8.59 KB
/
testng_run_modes.html
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
238
239
240
241
242
243
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.18">
<title>Running TestNG</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
</head>
<body class="article toc2 toc-left">
<div id="header">
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_running_testng">Running TestNG</a>
<ul class="sectlevel2">
<li><a href="#_eclipse_plug_in">Eclipse plug-in</a></li>
<li><a href="#_testng_idea_plug_in">TestNG IDEA Plug-in</a></li>
<li><a href="#_using_testng_with_gradle">Using TestNG with Gradle</a></li>
<li><a href="#_using_testng_with_maven">Using TestNG with Maven</a></li>
<li><a href="#_testng_ant_task">TestNG Ant Task</a></li>
<li><a href="#_running_testng_programmatically">Running TestNG programmatically</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="_running_testng">Running TestNG</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_eclipse_plug_in">Eclipse plug-in</h3>
<div class="paragraph">
<p>See <a href="https://testng.org/testng-eclipse/">the documentation</a> in the plugin repository.</p>
</div>
</div>
<div class="sect2">
<h3 id="_testng_idea_plug_in">TestNG IDEA Plug-in</h3>
<div class="paragraph">
<p>See <a href="https://www.jetbrains.com/help/idea/testng.html">the documentation</a> at JetBrains for more information.</p>
</div>
</div>
<div class="sect2">
<h3 id="_using_testng_with_gradle">Using TestNG with Gradle</h3>
<div class="paragraph">
<p>Gradle provides first class integration with TestNG and lets you run your TestNG tests.</p>
</div>
<div class="paragraph">
<p>Please refer to the <a href="https://docs.gradle.org/current/userguide/java_testing.html">Official Gradle Documentation</a> for more details.</p>
</div>
<div class="sect3">
<h4 id="_specifying_your_gradle_build_file">Specifying your Gradle build file</h4>
<div class="paragraph">
<p>The dependency in your project should look like the following:</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
For JDK-8 users
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="groovy">testImplementation 'org.testng:testng:7.5.1'</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
For JDK-11 users
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="groovy">testImplementation 'org.testng:testng:7.9.0'</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_using_testng_with_maven">Using TestNG with Maven</h3>
<div class="paragraph">
<p>Maven 2 supports TestNG out of the box without the need to download any additional plugins (other than TestNG itself). It is recommended that you use version 2.4 or above of the Surefire plugin (this is the case in all recent versions of Maven).</p>
</div>
<div class="paragraph">
<p>You can find the full instructions on the <a href="https://maven.apache.org/plugins/maven-surefire-plugin/">Maven Surefire Plugin</a> website. There are also <a href="https://maven.apache.org/plugins/maven-surefire-plugin/examples/testng.html">TestNG-specific instructions</a>.</p>
</div>
<div class="sect3">
<h4 id="_specifying_your_pom_xml">Specifying your pom.xml</h4>
<div class="paragraph">
<p>The dependency in your project should look like the following:</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
For JDK-8 users
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="xml"><dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5.1</version>
<scope>test</scope>
</dependency></code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
For JDK-11 users
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="xml"><dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
</dependency></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_sample_reports">Sample reports</h4>
<div class="paragraph">
<p><a href="samplereports/index.html" class="bare">samplereports/index.html</a></p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_testng_ant_task">TestNG Ant Task</h3>
<div class="paragraph">
<p>The ant extension and its <a href="https://testng.org/testng-ant">documentation</a> moved under its own repository.</p>
</div>
</div>
<div class="sect2">
<h3 id="_running_testng_programmatically">Running TestNG programmatically</h3>
<div class="paragraph">
<p>You can invoke TestNG from your own programs very easily:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="java">TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();</code></pre>
</div>
</div>
<div class="paragraph">
<p>This example creates a {javadocs-base-url}/org/testng/TestNG.html[TestNG] object and runs the test class Run2. It also adds a <code>TestListener</code>. You can either use the adapter class {javadocs-base-url}/org/testng/TestListenerAdapter.html[org.testng.TestListenerAdapter] or implement {javadocs-base-url}/org/testng/ITestListener.html[org.testng.ITestListener] yourself. This interface contains various callback methods that let you keep track of when a test starts, succeeds, fails, etc…​</p>
</div>
<div class="paragraph">
<p>Similarly, you can invoke TestNG on a testng.xml file or you can create a virtual testng.xml file yourself. In order to do this, you can use the classes found the package {javadocs-base-url}/org/testng/xml/package-frame.html[org.testng.xml]: {javadocs-base-url}/org/testng/xml/XmlClass.html[XmlClass], {javadocs-base-url}/org/testng/xml/XmlTest.html[XmlTest], etc…​ Each of these classes correspond to their XML tag counterpart.</p>
</div>
<div class="paragraph">
<p>For example, suppose you want to create the following virtual file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="xml"><suite name="TmpSuite" >
<test name="TmpTest" >
<classes>
<class name="test.failures.Child"/>
</classes>
</test>
</suite></code></pre>
</div>
</div>
<div class="paragraph">
<p>You would use the following code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="java">XmlSuite suite = new XmlSuite();
suite.setName("TmpSuite");
XmlTest test = new XmlTest(suite);
test.setName("TmpTest");
List<XmlClass> classes = new ArrayList<XmlClass>();
classes.add(new XmlClass("test.failures.Child"));
test.setXmlClasses(classes) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>And then you can pass this <code>XmlSuite</code> to <code>TestNG</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code data-lang="java">List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();</code></pre>
</div>
</div>
<div class="paragraph">
<p>Please see the {javadocs-base-url}/org/testng/package-summary.html[JavaDocs] for the entire API.</p>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-02-27 18:51:48 UTC
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/run_prettify.min.js"></script>
</body>
</html>