使用注释转换器禁用测试 class
Disable test class using annotation transformer
我正在尝试根据 excel 电子表格中设置的条件禁用包含测试方法的测试 Class。我已经实现了一个注释转换器,它根据条件禁用测试 class,但是它似乎无法禁用所需的测试 class,而是无法执行。我已经使用测试方法测试了 Annotation Transformer,并且它可以禁用它。下面是我的注释转换器。
int count=0;
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
try {
if(count==0) {
TestUtilities.getRunStatus();
}
} catch (Exception e) {
e.printStackTrace();
}
for(int i=0; i<TestUtilities.testCases.size(); i++) {
if(testClass.getName().equalsIgnoreCase(TestUtilities.testCases.get(i)))
{
if(TestUtilities.runStatus.get(i).equalsIgnoreCase("no")) {
annotation.setEnabled(false); //sets the enabled parameter for all the test cases based on the excel sheet input
break;
}
}
}
count++;
}
}
由于注释转换器满足多种条件,您需要在开始与参数交互之前先检查空值。
Class testClass
- 仅当在 class(Class 级注释) 之上找到 @Test
注释时才为 NON Null
Constructor testConstructor
- 仅当在 class 的构造函数 上找到 @Test
注释时才为 NON Null
Method testMethod
- 仅当在方法顶部找到 @Test
注释时才为 NON Null。
所以如果你所有的方法都有 @Test
注释那么你可能需要使用反射来找出方法所属的 class 然后添加你的逻辑 inclusion/exclusion相应地。
我正在尝试根据 excel 电子表格中设置的条件禁用包含测试方法的测试 Class。我已经实现了一个注释转换器,它根据条件禁用测试 class,但是它似乎无法禁用所需的测试 class,而是无法执行。我已经使用测试方法测试了 Annotation Transformer,并且它可以禁用它。下面是我的注释转换器。
int count=0;
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
try {
if(count==0) {
TestUtilities.getRunStatus();
}
} catch (Exception e) {
e.printStackTrace();
}
for(int i=0; i<TestUtilities.testCases.size(); i++) {
if(testClass.getName().equalsIgnoreCase(TestUtilities.testCases.get(i)))
{
if(TestUtilities.runStatus.get(i).equalsIgnoreCase("no")) {
annotation.setEnabled(false); //sets the enabled parameter for all the test cases based on the excel sheet input
break;
}
}
}
count++;
}
}
由于注释转换器满足多种条件,您需要在开始与参数交互之前先检查空值。
Class testClass
- 仅当在 class(Class 级注释) 之上找到 Constructor testConstructor
- 仅当在 class 的构造函数 上找到 Method testMethod
- 仅当在方法顶部找到@Test
注释时才为 NON Null。
@Test
注释时才为 NON Null
@Test
注释时才为 NON Null
所以如果你所有的方法都有 @Test
注释那么你可能需要使用反射来找出方法所属的 class 然后添加你的逻辑 inclusion/exclusion相应地。