TestNG testing.xml

通过三种方式调用TestNG

  • testing.xml
  • ant
  • command line
  • Eclipse
  • IntelliJ's IDEA

testing.xml sample

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
  
<suite name="Suite1" verbose="1" >
  <test name="Nopackage" >
    <classes>
       <class name="NoPackageTest" />
    </classes>
  </test>
 
  <test name="Regression1">
    <classes>
      <class name="test.sample.ParameterSample"/>
      <class name="test.sample.ParameterTest"/>
    </classes>
  </test>
</suite>

或者指定包名代替类名

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 
<suite name="Suite1" verbose="1" >
  <test name="Regression1"   >
    <packages>
      <package name="test.sample" />
   </packages>
 </test>
</suite>

或者运行指定的组和方法included excluded

<test name="Regression1">
  <groups>
    <run>
      <exclude name="brokenTests"  />
      <include name="checkinTests"  />
    </run>
  </groups>
  
  <classes>
    <class name="test.IndividualMethodsTest">
      <methods>
        <include name="testMethod" />
      </methods>
    </class>
  </classes>
</test>

或者不按照指定顺序,需要更改preserve-order属性为false.

<test name="Regression1" preserve-order="false">
  <classes>
 
    <class name="test.Test1">
      <methods>
        <include name="m1" />
        <include name="m2" />
      </methods>
    </class>
 
    <class name="test.Test2" />
 
  </classes>
</test>

command line sample:

假设环境变量中有TestNG。

java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]
Command Line Parameters
OptionArgumentDocumentation
-configfailurepolicyskip|continueWhether TestNG should continue to execute the remaining tests in the suite or skip them if an @Before* method fails. Default behavior is skip.
-dA directoryThe directory where the reports will be generated (defaults to test-output).
-dataproviderthreadcountThe default number of threads to use for data providers when running tests in parallel.This sets the default maximum number of threads to use for data providers when running tests in parallel. It will only take effect if the parallel mode has been selected (for example, with the -parallel option). This can be overridden in the suite definition.
-excludegroupsA comma-separated list of groups.The list of groups you want to be excluded from this run.
-groupsA comma-separated list of groups.The list of groups you want to run (e.g. "windows,linux,regression").
-listenerA comma-separated list of Java classes that can be found on your classpath.Lets you specify your own test listeners. The classes need to implement org.testng.ITestListener
-usedefaultlistenerstrue|falseWhether to use the default listeners
-methodsA comma separated list of fully qualified class name and method. For example com.example.Foo.f1,com.example.Bar.f2.Lets you specify individual methods to run.
-methodselectorsA comma-separated list of Java classes and method priorities that define method selectors.Lets you specify method selectors on the command line. For example: com.example.Selector1:3,com.example.Selector2:2
-parallelmethods|tests|classesIf specified, sets the default mechanism used to determine how to use parallel threads when running tests. If not set, default mechanism is not to use parallel threads at all. This can be overridden in the suite definition.
-reporterThe extended configuration for a custom report listener.Similar to the -listener option, except that it allows the configuration of JavaBeans-style properties on the reporter instance. 
Example: -reporter com.test.MyReporter:methodFilter=*insert*,enableFiltering=true 
You can have as many occurrences of this option, one for each reporter that needs to be added.
-sourcedirA semi-colon separated list of directories.The directories where your javadoc annotated test sources are. This option is only necessary if you are using javadoc type annotations. (e.g. "src/test"or "src/test/org/testng/eclipse-plugin;src/test/org/testng/testng").
-suitenameThe default name to use for a test suite.This specifies the suite name for a test suite defined on the command line. This option is ignored if the suite.xml file or the source code specifies a different suite name. It is possible to create a suite name with spaces in it if you surround it with double-quotes "like this".
-testclassA comma-separated list of classes that can be found in your classpath.A list of class files separated by commas (e.g. "org.foo.Test1,org.foo.test2").
-testjarA jar file.Specifies a jar file that contains test classes. If a testng.xml file is found at the root of that jar file, it will be used, otherwise, all the test classes found in this jar file will be considered test classes.
-testnameThe default name to use for a test.This specifies the name for a test defined on the command line. This option is ignored if the suite.xml file or the source code specifies a different test name. It is possible to create a test name with spaces in it if you surround it with double-quotes "like this".
-testnamesA comma separated list of test names.Only tests defined in a <test> tag matching one of these names will be run.
-testrunfactoryA Java classes that can be found on your classpath.Lets you specify your own test runners. The class needs to implement org.testng.ITestRunnerFactory.
-threadcountThe default number of threads to use when running tests in parallel.This sets the default maximum number of threads to use for running tests in parallel. It will only take effect if the parallel mode has been selected (for example, with the -parallel option). This can be overridden in the suite definition.
-xmlpathinjarThe path of the XML file inside the jar file.This attribute should contain the path to a valid XML file inside the test jar (e.g. "resources/testng.xml"). The default is "testng.xml", which means a file called "testng.xml" at the root of the jar file. This option will be ignored unless -testjar is specified.

或者在text文件中写入命令 c:\command.txt,然后让TestNG检索参数

C:> more c:\command.txt
-d test-output testng.xml
C:> java org.testng.TestNG @c:\command.txt

TestNG可以在Java虚拟机的命令行上传递属性

java -Dtestng.test.classpath="c:/build;c:/java/classes;" org.testng.TestNG testng.xml
System properties
PropertyTypeDocumentation
testng.test.classpath用分号分隔的包含测试类的一系列目录。TestNG将使用它来查找您的测试类,而不是类路径。如果您在XML文件中使用包标记,并且类路径中有很多类,其中大多数不是测试类,那么这将非常方便。
java org.testng.TestNG -groups windows,linux -testclass org.test.MyTest

如果您还指定一个testng.xml文件,那么指定应该运行哪些测试的命令行标志将被忽略,但-includedgroups和-exclude groups除外,它们将覆盖testng.xml中发现的所有组包含/排除。

Eclipse

Maven 插件安装好后

创建一个新的 TestNG 类

如果你现在有一个Java文件在编辑器中打开或如果你有在导航器中选择一个Java文件,向导的第一个页面将向您展示所有公共方法的类的列表,它会给你选择选择你想要测试的。您在此页上选择的每个方法都将包含在新TestNG类中,并带有一个引发异常的默认实现,因此您要记住实现它。

一旦创建了包含TestNG注释和/或一个或多个TestNG .xml文件的类,就可以创建TestNG启动配置。选择Run / Run…(或运行/调试…)菜单,并创建一个新的TestNG配置:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值