Running a Single Test with @BeforeTest annotated method in a separate class being run before the Test through testng Eclipse plugin

584 views
Skip to first unread message

Samit Sawant

unread,
Feb 25, 2015, 2:49:51 PM2/25/15
to testng...@googlegroups.com
Hi,


I have the following testng.xml

<suite name="TestAll">
 
<test name="test1">
<classes>
<class name="com.samit.Config" />
<class name="com.samit.TestA" />
                        <class name="com.samit.TestB" />
</classes>
</test>
 
<test name="test2">  
<classes>
<class name="com.samit.Config" />
<class name="com.samit.TestC" />
</classes>
</test>
 
</suite>


I have a maven project in eclipse and using the failsafe plugin I can run all these tests using maven install/verify command. The @BeforeTest/@AfterTest methods are part of the Config class and they correctly run before and after all the tests within the <test> tag

@BeforeTest Method
TestA
TestB
@AfterTest Method
@BeforeTest Method
TestC
@AfterTest Method

I can also run these by creating a TestNG Run configuration using testng eclipse plugin and  choosing the suite.xml option to point to the testng.xml file


My Question now is 

Using the testngplugin how can I run a single test with the @BeforeTest and @AftrerTest Config methods being run.
I can choose the "class" option in the run configuration but it only executes the @Test method from the class chosen without running @BeforeTest method from the Config class
The Config class just has @BeforeTest and @AfterTest methods.


Thanks,

Samit

plaint...@gmail.com

unread,
Feb 26, 2015, 4:25:13 AM2/26/15
to testng...@googlegroups.com
One possible workaround is to give groups to givent tests and than run it by setting up a group which have to be run.
Second (just tip) is to set always run to true (@BeforeTest(alwaysRun = true)) and try it that way. But I think, it will not work. I use always run when I have hierarchy of test classes and I want to run super.beforeMethod method always, despite that children class does not have an annotation on its method (because it is not overriding it).

Dňa streda, 25. februára 2015 20:49:51 UTC+1 Samit Sawant napísal(-a):
Reply all
Reply to author
Forward
0 new messages