【问题标题】:Using aspectJweaver while running testNG tests programatically在以编程方式运行 testNG 测试时使用 aspectJweaver
【发布时间】:2019-05-09 02:32:19
【问题描述】:

我正在使用 java 类从 excel 文件动态生成 testNG xml。我正在使用 allure-cli 在我的测试执行结束时生成诱惑报告。

我正在使用具有以下配置的 ma​​ven-surefire-plugin

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>

                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

当测试由 maven 目标和阶段触发时,我能够生成带有完整日志和屏幕截图的魅力报告,这些日志和屏幕截图由魅力注释(@step、@attachments、@Story ..)附加。

但是,当 java 类(生成 testNG xml 然后运行它)触发测试时,我无法获得相同的报告。 生成xml的代码是:-

public static  void runTestNGTests(Map<Integer,List<String>> testMap){

         TestNG myTestNG = new TestNG();     
         XmlSuite mySuite = new XmlSuite();
         mySuite.setName(suiteName);        


         List<XmlTest> myTests = new ArrayList<XmlTest>();

         for(Map.Entry<Integer, List<String>> map : testMap.entrySet()){


             XmlTest myTest = new XmlTest(mySuite);

             myTest.setName(map.getKey()+".) web Test : "+map.getValue().get(0) + " on "+ map.getValue().get(1));        
             myTest.addParameter("Date", map.getValue().get(0));
             myTest.setXmlClasses(Arrays.asList(new XmlClass("com.bravura.tests."+map.getValue().get(1))));

             myTests.add(myTest);
         }



         mySuite.setTests(myTests);

         List<XmlSuite> mySuites = new ArrayList<XmlSuite>();
         mySuites.add(mySuite);

            myTestNG.setXmlSuites(mySuites);
             myTestNG.run(); 
    }
}

我是否必须在我的testNG.xml 在诱惑报告中获取正确的测试主体日志?

【问题讨论】:

  • 在以编程方式运行 testNg 时,您是否找到了使注释工作并包含在魅力报告中的解决方案? .

标签: testng maven-surefire-plugin allure


【解决方案1】:
mySuite.addListener("path.to.your.listener");

此解决方案无需步骤即可为您提供报告。找不到收集步骤的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多