Maven + TestNG 打印@DataProvider的参数
Maven + TestNG Print parameters of @DataProvider
问题很简单,但我无法在任何地方找到它(谷歌搜索)我想 运行 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);
}
}
您可以使用自己的 Listener which will display the expected information. Then, configure surefire to use it: 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>
[...]
问题很简单,但我无法在任何地方找到它(谷歌搜索)我想 运行 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);
}
}
您可以使用自己的 Listener which will display the expected information. Then, configure surefire to use it: 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>
[...]