4-run
Testng can be called in multiple ways:
- Command Line
- Ant
- Eclipse
- Intellij's idea
This section only describes how to run testng from the command line. If you are interested in other methods, click the above link to view more information.
Assume that testng is already in your class path. The simplest call method is as follows:
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]
You must specify at least one XML file, which describes the testng suite you want to run. In addition, the following command line parameters are provided:
Command Line Parameters
Option |
Parameters |
Description |
-D |
Directory |
Directory generated by the report (default:Test-Output). |
-Excludegroups |
List of comma-separated groups |
List of groups to be excluded from the current running status |
-Groups |
List of comma-separated groups |
Group (e.g."Windows, Linux, regression"). |
-Listener |
A list of Java classes separated by commas (,). They can all be found in your class path. |
Let you specify your own listener. These classes need to be implementedOrg. testng. itestlistener |
-Parallel |
Method | Test |
If this parameter is specified, the default mechanism used during the test determines how to use parallel threads. Otherwise, no. This can be overwritten in the suite definition. |
-Reporter |
Custom report listener Extension Configuration |
Similar-ListenerOption. You can configure the style attribute of the JavaBean in the Report Server instance. For example: -Reporter com. Test. myreporter: methodfilter = * Insert *, enablefiltering = true This option is unlimited. It can be the same as needed. |
-Sourcedir |
List of directories separated by semicolons |
The directory where the source code of Annotation of the javadoc type is used. This option is useful only when you use javadoc annotations. (E.g."Src/test"Or"Src/test/org/testng/eclipse-plugin; src/test/org/testng"). |
-Suitename |
Default name of test suite
|
Specifies the name of the test suite defined in the command line. This option is ignored when different names are specified in suite. xml or source code. If double quotation marks are used, spaces can be used in the name. For example, "like this ". |
-Testclass |
List of comma-separated classes, which must be found in the class path |
List of test classes separated by commas."Org. Foo. test1, org. Foo. Test2"). |
-Testjar |
A jar file |
Specifies a jar file containing the test class. IfTestng. xmlIf the root directory of the JAR file is found, use it. Otherwise, all classes in the jar file will be treated as test classes. |
-Testname |
Default name used for testing |
It specifies the name of the test defined in the command line. This option is ignored when different names are specified in suite. xml or source code. If double quotation marks are used, spaces can be used in the name. For example, "like this ". |
-Testrunfactory |
Java class that can be found in the class path |
Let you specify your own test runner. The related classes must be implemented.Org. testng. itestrunnerfactory. |
-Threadcount |
Default number of threads used for parallel testing |
The maximum number of threads used in parallel operation. It is valid only when the parallel mode is used (for example, the-parallel option is used ). It can be overwritten in the suite definition. |
The preceding parameter description can be obtained by running testng without any parameters.
You can also place the command line switch in the file, for exampleC:/command.txtAnd then tell testng to use this file to parse its parameters:
C:> more c:/command.txt
-d test-output testng.xml
C:> java org.testng.TestNG @c:/command.txt
In addition, testng can also pass JVM parameters to it under the command line. For example:
java -Dtestng.test.classpath="c:/build;c:/java/classes;" org.testng.TestNG testng.xml
The following are attributes that testng can understand:
System attributes
Attribute |
Type |
Description |
Testng. Test. classpath |
A series of directories separated by semicolons, including your test class |
If this attribute is specified, testng searches for your test class instead of the class path. There are many classes in your class path, and most of them are not test classes, or they are used in XML files.PackageIt is very convenient to mark. |
Example:
java org.testng.TestNG -groups windows,linux -testclass org.test.MyTest
Note ant task and testng. XML allows you to use more parameters to run testng (methods to be included, specified parameters, and so on). Therefore, you should consider using the command line when learning testng, this will allow you to make rapid progress.