【问题标题】:Maven + TestNG Print parameters of @DataProviderMaven + TestNG 打印@DataProvider的参数
【发布时间】:2016-09-08 06:17:06
【问题描述】:

问题很简单,但我在任何地方都找不到(谷歌搜索)我想运行 mvn test 并在控制台输出中看到下一个文本“PASSED: theNameOfMyTest("A String Attribute")”生成此示例的代码看起来像这个:

import static org.testng.Assert.assertTrue;

public class TestClass {

    @DataProvider(name = "provider")
    public static Object[][] provider() {
        return new Object[][] {{"A String Attribute"}};
    }

    @Test(dataProvioder="provider")
    public void theNameOfMyTest(final String parameter) {
        assertTrue(true);
    }

}

【问题讨论】:

    标签: java maven testng dataprovider


    【解决方案1】:

    您可以使用自己的Listener,它将显示预期的信息。然后,配置surefire来使用它:https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

    public class MyTestListener extends TestListenerAdapter {
    
      @Override
      public void onTestFailure(ITestResult tr) {
        log("FAIL: ", tr);
      }
    
      @Override
      public void onTestSkipped(ITestResult tr) {
        log("SKIPPED: ", tr);
      }
    
      @Override
      public void onTestSuccess(ITestResult tr) {
        log("PASSED: ", tr);
      }
    
      private static void log(String prefix, ITestResult tr) {
        System.out.println(prefix + tr.getName() + "(" + Arrays.asList(tr.getParameters()) + ")");
      }
    }
    

    在你的pom.xml:

    [...]
    <plugins>
        [...]
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <properties>
                <property>
                  <name>listener</name>
                  <value>MyTestListener</value>
                </property>
              </properties>
            </configuration>
          </plugin>
        [...]
    </plugins>
    [...]
    

    【讨论】:

    • @Ordiel 如果这对您有用,请务必发布比参考更完整的解决方案 - 供后代使用
    • @BorisStrandjev 我刚刚添加了一个示例
    猜你喜欢
    • 1970-01-01
    • 2010-10-14
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2021-12-23
    • 1970-01-01
    相关资源
    最近更新 更多