单页网站仿制教程,网站免费域名申请,企业简介的网站怎么做,东莞市网站建设分站企业有时我们会遇到这样的问题#xff0c;比如如何多次运行一个测试用例#xff1f;invocationCount是这个问题的答案。在这篇文章中#xff0c;我们将讨论在TestNG中与Test annotation一起使用的invocationCount属性。
这个属性有什么作用#xff0c;或者调用计数有什么用比如如何多次运行一个测试用例invocationCount是这个问题的答案。在这篇文章中我们将讨论在TestNG中与Test annotation一起使用的invocationCount属性。
这个属性有什么作用或者调用计数有什么用invocationCount有助于多次执行单个测试用例。因此如果您有一个需要多次运行的测试用例invocationCount可以帮助您。
语法
TestinvocationCount num其中num 您希望运行此测试方法的次数。
示例
package Test;import org.testng.Assert;
import org.testng.annotations.Test;public class CodekruTest {Test(invocationCount 5) // now, this test case will run 5 timespublic void test2() {System.out.println(test2 is passed);Assert.assertTrue(true);}}
下面是运行上述测试类的XML文件
suite namecodekrutest namecodekruTestclassesclass nameTest.CodekruTest/class/classes/test
/suite
运行上述XML文件后的输出-
test2 is passed
test2 is passed
test2 is passed
test2 is passed
test2 is passed
PASSED: test2
PASSED: test2
PASSED: test2
PASSED: test2
PASSED: test2Default testTests run: 5, Failures: 0, Skips: 0所以在这里我们可以看到test运行了五次。
假设情景
如果我们保持invocationCount 0呢到时候会发生什么
在这里测试用例甚至不会运行如下面的示例所示
package Test;import org.testng.Assert;
import org.testng.annotations.Test;public class CodekruTest {Test(invocationCount 0) // now, this test case will run 5 timespublic void test2() {System.out.println(test2 is passed);Assert.assertTrue(true);}}
运行相同的XML文件后的输出- codekru
Total tests run: 0, Passes: 0, Failures: 0, Skips: 0在这里我们可以看到没有执行任何测试用例或方法。
如果我们将invocationCount保持为负值呢
它不会给予任何错误但是测试用例不会被执行。
package Test;import org.testng.Assert;
import org.testng.annotations.Test;public class CodekruTest {Test(invocationCount -2) // now, this test case will run 5 timespublic void test2() {System.out.println(test2 is passed);Assert.assertTrue(true);}}
产出- codekru
Total tests run: 0, Passes: 0, Failures: 0, Skips: 0