我正在并行运行我的测试. TestNG默认将线程名称设置为TestNG 难以浏览日志文件并区分消息. TestNG javadocs毫无帮助. 有什么办法可以设置线程名称或线程ID吗? 我在测试中设置了线程名称
TestNG默认将线程名称设置为TestNG
难以浏览日志文件并区分消息.
TestNG javadocs毫无帮助.
有什么办法可以设置线程名称或线程ID吗?
我在测试中设置了线程名称.例如,看看我是如何做到的 IN THIS PROJECT.基本上,我的所有Log4j消息(以及testNG报告消息)都显示其中的线程ID.这是一个基本示例,可以很容易地在标准输出中显示线程ID.您还可以使用Reporter类将threadid放入html标准中.不幸的是,你不能把strid放在HTML报告中的测试名称上,除非你写了一个自定义报告器(我在上面的项目链接中做了):
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ParallelMethodTest
{
@BeforeMethod
public void beforeMethod() {
long id = Thread.currentThread().getId();
System.out.println("Before test-method. Thread id is: " + id);
}
@Test
public void testMethodsOne() {
long id = Thread.currentThread().getId();
System.out.println("Simple test-method One. Thread id is: " + id);
}
@Test
public void testMethodsTwo() {
long id = Thread.currentThread().getId();
System.out.println("Simple test-method Two. Thread id is: " + id);
}
@AfterMethod
public void afterMethod() {
long id = Thread.currentThread().getId();
System.out.println("After test-method. Thread id is: " + id);
}
}
