[英]Maven + TestNG Print parameters of @DataProvider
The question is simple but I can't find it anywhere (googling) I want to run mvn test
and see in the console output the next text " PASSED: theNameOfMyTest("A String Attribute")
" the code that will produce this example would look something like this: 这个问题很简单,但是我想在任何地方都无法找到它(想查询),我想运行
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);
}
}
You can use your own Listener which will display the expected information. 您可以使用自己的侦听器 ,该侦听器将显示预期的信息。 Then, configure surefire to use it: https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html
然后,配置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()) + ")");
}
}
In your pom.xml
: 在您的
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>
[...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.