I am using Maven and TestNG to support my Selenium testing framework for a project.
I am using a custom test listener to report results into TestRail (our TCM tool). I am also using another custom test listener to handle cleaning up HAR files leftover by only a few tests.
Most of my test classes have only the TCM test listener specified like this:
@Test(groups = {"a", "b", "c"})
@Listeners({TestNGCaseResultsListener.class})
public class MyTestClass extends SeleniumTestRailTest { ... }
My Maven Failsafe POM includes section is:
<includes>
<include>**/folderOne/*.java</include>
<include>**/folderTwo/*.java</include>
<include>**/folderThree/**/**.java</include>
<include>**/folderFour/tests/*.java</include>
</includes>
I am not specifying test listeners in the POM, via the command line, nor am I using a TestNG suite XML file. The only times the listeners are specified is as annotations for the class as appropriate (see above).
If I issue this command to run one of the TCM-listener-only tests:
mvn -Dgroups=a verify
My HARfile cleanup listener (which is not attached to the test class that is running) will get fired off anyway when a test passes or fails.
Note that there is a test class that matches my Failsafe includes, which is annotated with the 'unwanted' listener. That class is in folderFour/tests/HARfiletest.java (following my includes described above.)
Is that listener being loaded up even though that class isn't being used? Is there a way to avoid this from happening? I only want test listeners annotated on classes that actually have tests run, not from any other classes.