当前位置: 首页 > news >正文

TestNG invocationCount属性

有时我们会遇到这样的问题,比如如何多次运行一个测试用例?invocationCount是这个问题的答案。在这篇文章中,我们将讨论在TestNG中与@Test annotation一起使用的invocationCount属性。

这个属性有什么作用,或者调用计数有什么用?invocationCount有助于多次执行单个测试用例。因此,如果您有一个需要多次运行的测试用例,invocationCount可以帮助您。

语法

@Test(invocationCount = 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 name="codekru"><test name="codekruTest"><classes><class name="Test.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: test2===============================================Default 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
===============================================
http://www.lryc.cn/news/300561.html

相关文章:

  • 关于maven项目中无法通过邮件服务器发送邮件的补充解决方案
  • 树形dp 笔记
  • 2024-02-08 Unity 编辑器开发之编辑器拓展1 —— 自定义菜单栏
  • typescript中的Omit排除类型及Pick取想要的属性
  • MATLAB计算极限和微积分
  • 在数组中插入元素
  • 【计算机网络】物理层|传输介质|物理层设备|宽带接入技术
  • TCP和UDP面试题提问
  • 网安常用的三个攻击方式
  • C++面向对象程序设计-北京大学-郭炜【课程笔记(二)】
  • IDEA Ultimate下载(采用JetBrain学生认证)
  • Matplotlib plt.plot数据可视化应用案例
  • ES实战--集群扩展
  • 【重要】django默认生成的表的意思记录
  • 12.3 OpenGL顶点后处理:平面着色
  • 实验5-6 使用函数判断完全平方数
  • AI 或许真的能助力中产阶级重塑辉煌 [译]
  • C#利用接口实现选择不同的语种
  • 设计模式-适配器模式 Adapter
  • 算法训练day29Leetcode491递增子序列46全排列47全排列Ⅱ
  • 内网穿透与搭建私人服务器
  • 交大论文下载器
  • 全栈笔记_浏览器扩展篇(manifest.json文件介绍)
  • 蓝桥杯每日一题(python)
  • 【Vue】工程化开发脚手架Vue CLI
  • 嵌入式培训机构四个月实训课程笔记(完整版)-Linux ARM驱动编程第三天-ARM Linux ADC和触摸屏开发 (物联技术666)
  • LeetCode “AddressSanitizer:heat-use-after-free on address“问题解决方法
  • 幸运彩票
  • 搭建yum仓库服务器
  • 贪心算法练习day1