TestNG系列-第五章 测试方法、测试类和测试分组(续5)-9类级别注解、并发、失败情况

来源:互联网 发布:hp网络打印机驱动 编辑:程序博客网 时间:2024/05/01 10:01
9 类级别的注解
@Test可以放在类上:
@Testpublic class Test1{public void test1(){}     public void test2(){}}

@Test在类上的效果使得类中所有的公共方法都变成测试方法。同时如果为了增加一些确定的属性也可以重复地在一个方法上增加@test。如:
@Testpublic class Test1{public void test1(){}@Test(groups="g1")public void test2(){}}

10 并行和超时

<suite>标签的并行属性可以使用下面中的一个
<suite name="My suite" parallel="methods" thread-count="5">
parallel="methods":TestNG会在分离的线程中运行所有的测试方法。依赖的方法也会在不同的线程执行,并且会按照当时指定的顺序执行。
<suite name="My suite" parallel="tests" thread-count="5">
parallel="tests":TestNG在同一个线程运行在相同标签<test>的线程。但是每一个标签<test>运行的在不同的线程上。这就允许对所有在相同的标签<test>运行时具有线程不安全的类进行分组,以保证他们在相同的线程运行并且有效利用线程执行测试。
<suite name="My suite" parallel="classes" thread-count="5">
parallel="classes": TestNG将同一个类中所有方法在相同的线程运行,而每个类会在分离的线程中运行。
<suite name="My suite" parallel="instances" thread-count="5">
parallel="instances": TestNG会将所有在同一个实例的方法运行在相同的线程上,在不同实例的的两个方法会在不同的线程运行。

注:@test属性timeOut在并行和非并行模式下都生效。

也可以指定@Test的方法在不同的线程上调用。
@Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000)public void testServer() {}

11 返回失败测试
在一个测试集中每次运行失败,在输出路径中会创建一个名为testng-fail.xml的文件。这个xml文件包含的关于失败方法的必要信息,这些信息可以让你快速的重现失败用例而不用运行所有的测试。典型回话形式:
java -classpath testng.jar;%CLASSPATH% org.testng.TestNG -d test-outputs testng.xmljava -classpath testng.jar;%CLASSPATH% org.testng.TestNG -d test-outputs test-outputs\testng-failed.xml

注: testng-failed.xml 也会包含所有依赖方法。
0 0