这里我的意图是,根据之前的方法条件,该@Test
方法需要启用或禁用但是在下面的代码中,即使我通过了测试用例名称,它也没有被跳过?谁能建议我解决方案?
我需要BeforeTestMethod
在我的实际代码中检查一些逻辑,并基于此我必须@Test
在类文件中启用
public class ListnerClass implements IAnnotationTransformer {
public static String testName;
public void transform(ITestAnnotation iTest, Class testClass, Constructor testConstructor, Method method) {
if(method.getName().equalsIgnoreCase(testName)) {
iTest.setEnabled(false);
}
}
public class TestNGTest3 {
@BeforeMethod
public void setUp(Method result) {
System.out.println("This is the before Method getting name "+result.getName());
if(result.getName().contains("3"))
{
ListnerClass.testName=result.getName();
}
}
@Test
public void testMethod3() {
System.out.println("This is the Method of Method");
}
@Test
public void testMethod4() {
System.out.println("Hi");
}
}
TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name=" Regression Suite">
<listeners>
<listener class-name="com.listners.ListnerClass" />
</listeners>
<test thread-count="1" name="Test">
<classes>
<class name="com.test.TestNGTest3" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
输出:
This is the before Method getting name testMethod3
This is the Method of Method
This is the before Method getting name testMethod4
Hi