Invocation order of configuration methods

23 views
Skip to first unread message
Message has been deleted
Message has been deleted

testng user

unread,
Dec 18, 2009, 6:50:36 PM12/18/09
to testng-users
Hello,

I have issues in invoking the configuration methods in my test code.
Here is the pseudo code.

Class Test
{

@Parameters({"a","b","c"})
@BeforeSuite
public void setUp
{
//Set values read from the testng.xml file
}

@BeforeClass
public void createSession()
{
//Using the server connection parameters read in the setUp method
create a session
}

@BeforeGroup
public void runStartupTasksBeforeTest()
{
//Start and stop multiple servers.
//This method has to be called before methods are executed in each
group
}

@Test(groups= {"windowsTests"}, dataProvider="windows")
public void testRunWindowsTestsInSequence(TestData oData)
{
// The parameter for this method is passed by dataprovider
}

@Test(groups= {"windowsTests"}, threadPoolSize = 5, invocationCount
= 2, dependsOnMethods ="testRunWindowsTestsInSequence" )
public void testRunWindowsTestsInParallel()
{
}

@DataProvider(name = "windows")
public Iterator getWindowsIterator() {
return new DataIterator("WINDOWS");
}

}


//Sample testng configuration file


<suite name="OSTest" junit="false" annotations="JDK">


<parameter name="a" value="127.0.0.1"/>
<parameter name="b" value="administrator"/>
<parameter name="c" value="password"/>


<test verbose="2" name="Windows Tests" annotations="JDK5">
<groups>
<run>
<include name="windowsTests"/>
</run>
</groups>
<classes>
<class name="Test"/>
<methods>
<include name="testRunWindowsTestsInSequence"/>
<include name="testRunWindowsTestsInParallel"/>
</methods>
</classes>
</test>
</suite>

The BeforeSuite and BeforeClass annotated methods are not called and
the methods in the group require session details to run the tests.

Am I missing something here?

Thanks.

Jek

unread,
Dec 22, 2009, 12:27:09 PM12/22/09
to testng-users
Hi,

Your configuration methods (@BeforeSuite & @BeforeClass) must also be
in the desired group. When running in a group context, only those
methods in the specified groups will be executed. That includes
configuration methods. It is best to look at the running of a
configuration method as if were a test. This behavior initially
confused us as well.

If you always want the configuration methods to run regardless of
group, then set alwaysRun=true.

Cheers,

-John

testng user

unread,
Dec 22, 2009, 1:00:36 PM12/22/09
to testng-users
Hello John,

Many thanks for your reply.

I have few more questions regarding the grouping concepts.

1. Are the configuration methods inherited?

Eg.

@Test(groups = {"All"})
class SuperTests
{
@BeforeSuite(groups = {"All"},alwaysRun=true)
public void setUp()
{
//Set values from testng configuration xml file
}
}

Class SubClass extends SuperClass
{

@Test(groups = {"windowsTests"})
{
}

@Test(groups = {"linuxTests"})
{
}

@Test(groups = {"macTests"})
{
}

}

After running the tests when I look at the index.html file in the test
output directory, I see tests (windows, linux and mac group methods
included under All groups.

Pls. confirm.

Thanks

abhishek uppala

unread,
Dec 22, 2009, 9:57:58 PM12/22/09
to testng...@googlegroups.com
Hi John,

Inclusion of windows, linux and mac group methods under the group All is correct. This is in accordance with partial grouping, which means, when a class is annotated to belong to some group(in your case, All), all of its methods also belong to the same group, in addition to the groups that individual methods may belong to.

So, in your case, method

@Test(groups = {"windowsTests"})
{
}

belongs to the groups 'All' and "windows Tests"

Hope this helps clarify your question.


Thanks
Abhishek Uppala
--

You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


Reply all
Reply to author
Forward
0 new messages