您的位置:首页 > 其它

TestNG系列-第四章 testNG之命令行运行及参数详解

2016-11-08 22:32 661 查看
1 调用TestNG方法

1.1 命令行
1.2
ant(http://testng.org/doc/ant.html
1.3
Eclipse (http://testng.org/doc/eclipse.html)
1.4
IntelliJ's IDEA (http://testng.org/doc/idea.html

2 这里只介绍使用命令行调用。当在类路径配置了testNG之后,可以使用如下方法调用
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]


3 命令行参数

OptionArgumentDocumentation
-configfailurepolicyskip|continue在测试集(suite)中的@Before运行失败的情况下,是否继续执行测试,默认是忽略
-d目录生成报告的目录,默认是 test-output.
-dataproviderthreadcount并发运行时启动dataprovider的线程数量设置用于启动测试的最大线程默认值,只有在并发运行模式下才会生效。在测试集定义中可以被重写(override)
-excludegroups逗号分隔的组列表不包含的组列表
-groups逗号分隔的列表要运行的组列表(例如 "windows,linux,regression")
-listener可以在classpath路径中找到的逗号分隔的类列表指定测试的listener. 这个类需要实现接口org.testng.ITestListener
-methods都好分隔的类名称和方法的列表。如com.example.bar.f2。指定单独运行的测试方法
-methodselectors一个逗号分隔的java类和方法定义方法选择器优先级列表。命令行指定方法选择器。如: com.example.Selector1:3,com.example.Selector2:2
-parallelmethods|tests|classes如果指定了,设置用于确定如何在运行测试时使用并行线程的默认机制。如果没有设置,默认机制是不使用并行线程在所有。这可以在套件定义重写。
-reporter扩展自定义报告listener的配置.类似 -listener 选项, 除了容许reporter示例上由javabean形式的配置.

    例如: -reporter com.test.MyReporter:methodFilter=*insert*,enableFiltering=true
-sourcedir分号隔开的目录列表带有javadoc注释的测试源文件目录. 这个选项只在使用javadoc类型的annotation时才有效. 

                        (例如 "src/test" or "src/test/org/testng/eclipse-plugin;src/test/org/testng/testng").
-suitename默认测试集合名称在命令行指定一个测试集名称。如果在suite.xml或者源代码中指定了一个不同的名称,这个设置将会被忽略。
-testclass逗号分隔的测试类列表,这些类能在类路径中找到如. "org.foo.Test1,org.foo.test2").
-testjarA jar file.指定一个包含测试类的jar文件。若在jar文件中有testng.xml则会使用这个testng.xml。否则会运行jar文件中所有的测试类
-testname默认的测试名在命令行中指定测试类名称。若在testng.xml有不同的配置,这个配置将被忽略。".
-testnames逗号分隔的测试类名称只会运行与<test>标签匹配的
-testrunfactory在类路径能找到的java类Lets you specify your own test runners. The class needs to implement org.testng.ITestRunnerFactory.
-threadcount默认的并发运行的线程数量设置默认并发运行时最大的线程数量。只有当设置了并发模式时,这个配置才会生效。
-xmlpathinjarjar文件中xml文件的路径该属性包含在测试的jar文件中的有效xml文件的路径如 "resources/testng.xml"。默认的tesng.xml 在jar文件的根路径下。如果不指定-testjar,这个属性会被忽略。
4 也可以将命令行切换放在文本文件。
比如:

c:> more c:\command.txt
-d test-output testng.xml
C:> java org.testng.TestNG @c:\command.txt
除此之外,TestNG can be passed properties on the command line of the Java Virtual Machine, for example

java -Dtestng.test.classpath="c:/build;c:/java/classes;" org.testng.TestNG testng.xmL
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息