有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java动态设置测试注释

我想创建一个数据驱动的框架,测试将基于excel中的数据执行

当前,当我执行测试时,所有结果仅在一个testName下

我要寻找的是,每个迭代都应该被视为单独的测试


共 (1) 个答案

  1. # 1 楼答案

    无法在运行时向现有类添加注释;见Adding Java Annotations at Runtime。问:;A建议使用Proxyto或适配器来处理这个问题,但我认为这种方法不适用于TestNG测试

    你可能需要采取不同的方法^TestNG文档的{a2}有一个示例,演示了如何以编程方式在测试类中运行测试:

    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...

    然后Section 5.17解释如何使用方法拦截器来处理要调用的方法列表。最后Section 5.18解释了告诉TestNG使用侦听器(如方法拦截器)的各种方法

    如果将这些与用于从Excel电子表格中提取数据的代码结合使用,并以编程方式运行相关的测试类或测试方法