Any way to define suite level dependency when running TestNG programmatically?

961 views
Skip to first unread message

Gaurav Gupta

unread,
Jan 6, 2012, 6:18:36 PM1/6/12
to testng-users
Hi All,

Is there any way to define suite level dependencies when running
TestNG programmatically? That is, suite A should only start after
suite B has finished. I have seen some other related posts but none
when creating and running multiple suites programmatically.

More details:
Our QA tests are created in Excel where each worksheet is a separate
suite. Through the code, we are creating XmlSuite(s) from the excel
data, creating TestNG object and then running them concurrently.
Here's code overview:

---
testng = new TestNG();
testng.setPreserveOrder(true);
testng.setSuiteThreadPoolSize(2);

List<XmlSuite> suites = new ArrayList<XmlSuite>();
//------create multiple suites
XmlSuite suite = new XmlSuite();
//...add tests
//
suites.add(suite)


testng.setXmlSuites(suites);
testng.run();
---

Here, is there any way to specify that certain suite should start only
after certain other suite has finished running, even if there's a free
thread available? I can't add group dependencies because tests are in
different suites.

To demonstrate, here's a simplified version : https://gist.github.com/1572820

So in this example, I create 4 suites, 2 that run fast (Suite 0 & 2)
and 2 that are slow (Suite 1 & 3). I set the suite thread pool size to
2. The suites are added in order 0, 1, 2, 3. When I run it, Suites 0 &
1 start. Since 0 is fast, it finishes quickly. Then Suite 2 is
started, which also finishes before Suite 1. Now Suite 3 is started
but I would like it to wait until suite 1 is completed.

----------

Thanks in advance,

-Gaurav

Krishnan Mahadevan

unread,
Jan 10, 2012, 5:09:51 AM1/10/12
to testng...@googlegroups.com
Gaurav,
Have you tried the xml version wherein you are creating a master suite which comprises of SuiteA and SuiteB.

Have you been able to define SuiteB as depending upon SuiteA ?

I dont think that sort of a dependency exists within TestNG.

AFAIK, TestNG lets you establish dependencies only on either 

a) Methods (or)
b) Groups.

So you might have to play with only these two to get your task done.

Another alternative that I can think of is to leverage an AnnotationTransformer and then use it for your convenience. However note that the AnnotationTransformer still lacks the capability wherein for an incoming object of type "ITestAnnotation" which represents a method annotated with @Test, you still wouldnot be able to query information pertaining to what XMLTest and what XMLSuite does this @Test annotated method belong to. It can only retrieve the information that you would have furnished in the @Test method.

That being said, within the AnnotationTransformer.transform() method you would have to write up an adhoc logic wherein you figure out what method belongs to what suite (perhaps have this in a properties file) and then dynamically do dependency injection.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"




--
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.


Gaurav Gupta

unread,
Jan 12, 2012, 9:19:59 PM1/12/12
to testng-users
Thanks Krishnan,

I was able to do this by setting 1 suite as the child of another
suite.
-----------
suite.setParentSuite(pSuite);
pSuite.getChildSuites().add(suite);
-----------

In this way, the child suite is always run and completed before
starting parent suite.

-Gaurav

On Jan 10, 2:09 am, Krishnan Mahadevan

Krishnan Mahadevan

unread,
Jan 12, 2012, 9:36:13 PM1/12/12
to testng...@googlegroups.com
Cool. I must admit I didnt know about child suites though. Thanks for sharing this info. So would this child suite concept have an equivalent in the xml format as well?
--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

Cédric Beust ♔

unread,
Jan 12, 2012, 9:51:27 PM1/12/12
to testng...@googlegroups.com
On Thu, Jan 12, 2012 at 6:36 PM, Krishnan Mahadevan <krishnan.ma...@gmail.com> wrote:
Cool. I must admit I didnt know about child suites though. Thanks for sharing this info. So would this child suite concept have an equivalent in the xml format as well?

Yes, it's <suite-files>.

-- 
Cédric

Gaurav Gupta

unread,
Jan 17, 2012, 5:37:28 PM1/17/12
to testng-users
Cedric,

The <suite-files> work when running through testng.xml or using
testng.setTestSuites(Arrays.asList("testng.xml")) (to use an already
existing xml file).
But if I create the XmlSuite through code and then set the child suite
using setSuiteFiles(), it doesn't run the child suites.
The test file to demonstrate the issue is here: https://gist.github.com/1629341
and I also opened a bug here: https://github.com/cbeust/testng/issues/159

I looked through TestNG class and modified it to fix the issue. I'll
submit a pull request but your comments/feedback is appreciated.

-Gaurav

On Jan 12, 6:51 pm, Cédric Beust ♔ <ced...@beust.com> wrote:
> On Thu, Jan 12, 2012 at 6:36 PM, Krishnan Mahadevan <
>

Gagandeep Singh

unread,
Jul 25, 2019, 4:27:19 PM7/25/19
to testng-users
So, what will happen if your tests in Child suite fail? Will it still run the Parent suite? I have actually tested it and it does still run the parent suite but what if, if I dont want the parent suit to run in case any of the test in the child suite fails? Any solutions please? 

Krishnan Mahadevan

unread,
Jul 25, 2019, 11:00:59 PM7/25/19
to testng...@googlegroups.com

TestNG will continue to run all the suites. TestNG doesn’t decide its execution decision based on the execution outcome of a particular suite.

 

The suite of suites was merely provided as a way to consolidate multiple suites into one for ease of reference and execution. AFAIK, it doesn’t have any other extra attributes to it in terms of value add.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

--

You received this message because you are subscribed to the Google Groups "testng-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/68c6b8aa-3ed4-4942-a6be-7eef19ea6b62%40googlegroups.com.

Uttam uttam

unread,
Sep 8, 2020, 3:20:37 AM9/8/20
to testng-users
Hi,

I tried to create a suite  and add its parent suite.

List<XmlSuite> suites = new ArrayList();

XmlSuite xSuiteB = new XmlSuite();
// Create suite and set tests
xSuiteB.setName("Suite-B");

 
XmlSuite xSuiteA = new XmlSuite();
// Create suite and set tests
xSuiteA.setName("Suite-A");
xSuiteB.setParentSuite(xSuiteA);
suites.add(xSuiteA)
suites.add(xSuiteB)


TestNG testng = new TestNG();
// Set suite to the executor
testng.setXmlSuites(suites);
testng.run();

I want the order of execution to be Suite-B followed by Suite-A .But its not happening, isn't the child suite runs first followed by parent suite ? (Using latest TestNg Library 7.4 version )
This mail contains confidential information intended only for the individual(s) named. If you’re not the named addressee, don’t disseminate, distribute or copy this e-mail. Please notify the sender immediately and delete it from your system.If you wish not to receive such e-mails you may reply with text “Unsubscribe”.
Reply all
Reply to author
Forward
0 new messages