【发布时间】:2016-08-23 12:52:10
【问题描述】:
我正在尝试为特定测试用例设置调用计数。以下代码是为侦听器编写的。目标是将特定测试方法循环给定次数。侦听器工作正常,但 setInvocationCount 未按预期工作。
监听类:-
public class InvokedListener implements IInvokedMethodListener {
String count = System.getProperty("count", "100");
int counter = Integer.parseInt(count);
int count1;
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
System.out.println("before invocation of " + method.getTestMethod().getMethodName());
String methodName = method.getTestMethod().getMethodName();
if (methodName.contains("TC_02_InstructorCreatesCourse")) {
System.out.println("The listener is activated for:-" + method.getTestMethod().getMethodName());
method.getTestMethod().setInvocationCount(20);
System.out.println("Invocation count is set to :-" + counter);
}
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
System.out.println("after invocation " + method.getTestMethod().getMethodName());
}
testNG xml:-
<?xml version="1.0" encoding="UTF-8"?>
<listener class-name="InvokedLister" />
</listeners>
<test name="CourseCreation"
preserve-order="true" enabled="true">
<classes>
<class
name="TestCases" />
</classes>
</test>
测试用例:-
@Test
public void TC_01_LoginToSSOApplicationViaInstructor() {
System.out.println("1");
}
@Test
public void TC_02_InstructorCreatesCourse() {
System.out.println("2");
}
@Test
public void TC_03_LoginToSSApplicationViaStudent() {
System.out.println("3");
}
@Test
public void TC_04_EnrollStudentInCourse() {
}
【问题讨论】:
标签: java automation automated-tests testng listeners