Reputation: 1
I need to print this before actual execution of tests start. Anyways, we get the count at last of execution.
Say for example if my testng.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
<test name="test1">
<groups>
<run>
<include name="functest" />
</run>
</groups>
<classes>
<class name="GroupTestExample" />
</classes>
</test>
</suite>
And there are 10 methods in class GroupTestExample which comes under group functest, it should print 10 in log as soon as it starts running.
Upvotes: 0
Views: 865
Reputation: 3628
Create a custom Listener which extends the org.testng.TestListenerAdapter
. After that override the following method:
public class MyCustomListener extends TestListenerAdapter {
@Override
public void onStart(ITestContext testContext) {
super.onStart(testContext);
System.out.println("Number of Test Methods: " + testContext.getAllTestMethods().length);
}
}
You can add your custom listener by using @Listeners
annotation on your main class of your test, like
@Listeners({MyCustomListener.class})
public class MyMainTestClass { ... }
You can find more information in TestNG doc:
TestNG Listeners - http://testng.org/doc/documentation-main.html#testng-listeners
Upvotes: 1