How to structure the test methods here?

46 views
Skip to first unread message

Vinayak Kini

unread,
Aug 17, 2020, 9:40:17 PM8/17/20
to testng-users
If I have test cases which have to be run for 6 users but the implementations of a test case may not be the same for the users then how should I write my @Test?

SearchEntity  same implementation for all 6 users  
UpdateEntity all 6 are different
CreateEntity   is same for user 1,2,3 but a different implementation for 4 and 5 each

Currently in my test classes I have 1 @Test method with the same name as the test case in the Excel sheet

public class SearchEntity{
   HashMap<> data;

    @Factory( dataProvider = getTestData)
    public SearchEntity(HashMap<> data){
        this.data = data;
    }

   @Test
   public void testMethod(){
       /* test logic */
   }
}

My virtually created XML can look like :

<suite>
   <test name="user1">
      <classes>
         <class name=" SearchEntity" />
          ..
         <class name=" SearchEntity " />
         <class name=" CreateEntity " />
          ..
          <class name=" CreateEntity " />
       </classes>
    </test>
   
      <test name="user2">
      <classes> 
         <class name="PrintPerson" /> 
          .. 
         <class name="PrintPerson" />
         <class name="SearchPerson" />
          ..
          <class name="SearchPerson" /> 
       </classes>
    </test> 
<suite/>




Vinayak Kini

unread,
Aug 21, 2020, 1:06:43 PM8/21/20
to testng-users
Hi can anyone help me with this ?

Nisarg Dave

unread,
Aug 22, 2020, 2:00:20 AM8/22/20
to testng...@googlegroups.com
So far, I think you have 2 ways

1. Have flag based mechanism with if else loops 

Have a parameter (of a user with which you want to run) in testng file --> read that parameter value in test case & based on if else run your updateEntity method.


2. Have flag based mechanism with  abstraction implementation. 

Have a parameter (of a user with which you want to run) in testng file --> read that parameter value in test case &  create an interface having method updateEntity. Create classes which implement the interface & can have different implementation for the updateEntity. 

Now using Java reflection APIs, you can create instance of a class from which you want to run the updateEntity and then it would be simple. Write object.updateEntity and it will call the one which you want for specific user.

Regards,
Nisarg
9725626638
-----------------------

   

--
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/c55c6c87-7a27-4cf9-bcc6-e33ce7e55944n%40googlegroups.com.

Vinayak Kini

unread,
Aug 22, 2020, 11:39:36 AM8/22/20
to testng-users
I've done something similar to the 2nd method you mentioned, thanks Nisarg
Reply all
Reply to author
Forward
0 new messages