Adding depends-on properties to @Test programmatically

26 views
Skip to first unread message

VanderRock s

unread,
Mar 15, 2022, 11:06:10 PM3/15/22
to testng-users
I have an initialize test class that includes test methods that do some initialization setup for the rest of the classes. My initialize class looks as follows:

public class TP397_Procedure1_Initialize extends BaseClass
{
        @FrameworkAnnotation(author = { "author" }, deviceType="abc")
        @Test(description="Delete All Patients", groups="Primary" )
        public void deleteAllPatients()
        {        
             .
             .
             .
        }

        @FrameworkAnnotation(author = { "author" }, deviceType="abc")
        @Test(description="Create new patient", groups="Primary" )
        public void createNewPatients()
        {        
             .
             .
             .
        }
  and so on...
}

I want the rest of the classes to be dependent on this class. So even if a single @Test fails in initialize, all the @Tests in the rest of the classes should skip.

I was able to achieve this using the suggestion by tind...@gmail.com in the following post:

My question is, instead of manually expecting test writers to add the groups to all their testcases, (which they might forget to do for some), can I programmatically have all my tests under all classes except class initialize automatically get this depends on groups added to each @Test? 
So it should look as follows:

@Test(description = "OR Session Is Not Created When IPG And Lead Details Are Not Configured", priority = 0, groups= {"Dependency"})

My suite xml will be as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TP397_Procedure1">
  <test thread-count="5" name="Procedure1">
          <parameter name="TP_ID" value="TP397" />
        <parameter name="deviceName" value="R52N20ALVDN" />
        <parameter name="platformVersion" value="10" />
        <parameter name="portNumber" value="4723" />
        <groups>
                <dependencies>
                        <group name="Dependency" depends-on="Primary" />
                </dependencies>
        </groups>
    <classes>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Initialize"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section01"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section02"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section03"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section04"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section05"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section06"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section07"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section08"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section09"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_Section10"/>
      <class name="CPAutomationTestSuite.TP_000397.Procedure1.TP397_Procedure1_TearDown"/>
Thank you

⇜Krishnan Mahadevan⇝

unread,
Mar 16, 2022, 5:13:29 AM3/16/22
to testng-users
You should take a look at IAnnotationTransformer. That should basically do what you are looking for.

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/
My Technical Scribblings @ https://rationaleemotions.com/


--
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/8cf105d0-97cb-44ec-8ba9-2c967af943bbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages