TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();
This example creates a TestNG object and runs the test class Run2. It
also adds a TestListener. You can either use the adapter class
org.testng.TestListenerAdapter or implement org.testng.ITestListener
yourself. This interface contains various callback methods that let
you keep track of when a test starts, succeeds, fails, etc...
# 1 楼答案
无法在运行时向现有类添加注释;见Adding Java Annotations at Runtime。问:;A建议使用
Proxy
to或适配器来处理这个问题,但我认为这种方法不适用于TestNG测试你可能需要采取不同的方法^TestNG文档的{a2}有一个示例,演示了如何以编程方式在测试类中运行测试:
然后Section 5.17解释如何使用方法拦截器来处理要调用的方法列表。最后Section 5.18解释了告诉TestNG使用侦听器(如方法拦截器)的各种方法
如果将这些与用于从Excel电子表格中提取数据的代码结合使用,并以编程方式运行相关的测试类或测试方法