我正在从maven pom.xml执行testng.xml,并在testng.xml中指定threadcount = 5。出于调试目的,我需要在日志中打印threadID但不能这样做。以下是配置详细信息: -
Pom.xml
-------
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
Testng.xml
----------
<suite name="Functionality Test" parallel="tests"
verbose="5" thread-count="5" configfailurepolicy="continue" >
<test name="Industry Brief" >
<classes>
<class name="com.firstrain.XX" />
</classes>
</test>
<test name="FR Labs">
<classes>
<class name="com.firstrain.YY" />
</classes>
</test>
</suite>
Log4j.properties pattern Layout
-------------------------------
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
Current Output
-------------
INFO [TestNG] (XX.java:27) - testme XX
INFO [TestNG] (YY.java:25) - testme YY
INFO [TestNG] (YY.java:26) - 1234
INFO [TestNG] (XX.java:27) - testme XX again
INFO [TestNG] (YY.java:47) - testme YY again
Expected Output
-------------
INFO [pool-1-thread-1] (XX.java:27) - testme XX
INFO [pool-1-thread-2] (YY.java:25) - testme YY
INFO [pool-1-thread-2] (YY.java:26) - 1234
INFO [pool-1-thread-1] (XX.java:27) - testme XX again
INFO [pool-1-thread-2] (YY.java:47) - testme YY again
答案 0 :(得分:0)
您可以使用以下行来区分并行执行中的线程
Thread.currentThread().getId()
或者您可以使用
设置线程的名称Thread.currentThread().setName(name)
并使用
检索它Thread.currentThread().getName()