testng翻译之四--Running TestNG

来源:互联网 发布:阿里云服务器五折 编辑:程序博客网 时间:2024/06/05 06:05

TestNG可以以不同的方式调用:

  • command line
  • [ant]
  • [Eclipse]
  • [IntelliJ’s IDEA]

本节仅解释如何从命令行调用TestNG。 如果您对其他方式感兴趣,请点击上面的链接。


假设你的类路径中有TestNG,调用TestNG的最简单的方法如下:

java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]

您需要指定至少一个XML文件,描述您尝试运行的TestNG套件。 此外,以下命令行开关可用:

option Argument Documentation -configfailurepolicy skip / continue TestNG是否应继续执行套件中的其余测试,如果@ Before***方法失败,则跳过它们。 默认行为是跳过。 -d A directory 将生成报告的目录,默认为test-out -dataproviderthreadcount 并行运行测试时,用于data providers程序的默认线程数。 这将设置并行运行测试时数据提供程序使用的默认最大线程数。 它将仅在选择并行模式(例如,使用-parallel选项)时生效。 这可以在套件定义中覆盖。 -excludegroups 逗号分隔的组列表 要从运行中排除的组的列表。 -groups 逗号分隔的组列表 要运行的组的列表,例如”windows” 、”linux”、”regression”。 -listener 可在类路径中找到的Java类的逗号分隔列表。 让您指定自己的测试侦听器。 类需要实现org.testng.ITestListener。 -methods 完全限定类名和方法的逗号分隔列表。 例如com.example.Foo.f1,com.example.Bar.f2。 您可以指定单独的方法运行。 -methodselectors -parallel -reporter -sourcedir -suitename -testclass -testjar -testname -testnames -testrunfactory -threadcount -xmlpathinjar

当然,也可以不适用任何参数来调用 testng.xml。


您还可以将命令行放在一个文本文件中,例如c:\ command.txt,并告诉TestNG使用该文件来检索其参数:

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

此外,例如,可以在Java虚拟机的命令行上传递TestNG的属性.

java -Dtestng.test.classpath="c:/build;c:/java/classes;" org.testng.TestNG testng.xml

对testng属性的理解:

Property Type Documentation testng.test.classpath 以分号分隔的一系列目录,其中包含您的测试类。 如果设置了此属性,TestNG将使用它来查找您的测试类,而不是类路径。 如果您在XML文件中使用包标记,并且在类路径中有很多类,那么这很方便,其中大多数类不是测试类。

Example:

java org.testng.TestNG -groups windows,linux -testclass org.test.MyTest

ant任务和testng.xml允许您使用更多的参数(要包括的方法,指定参数等)启动TestNG,那么当您试图了解TestNG,并且想要快速启动和运行testng时,命令行是个不错的选择。

0 0