How to set thread name in TestNG -
i'm running tests in parallel. testng default set name of threads testng
makes difficult browse through log files , differentiate between messages.
testng javadocs of no help.
is there way can set thread name or thread id?
i set thread name in tests. example, see how did in project. basically, log4j messages (as testng reporter messages) show thread id in them.
here basic example, makes easy show thread id in standard output. can put threadid in html standard out using reporter
class. unfortunately can't put threadid on test name in html report unless write custom reporter (which did in link project above):
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); } }
Comments
Post a Comment