What would you like to see added into TestNG?

96 views
Skip to first unread message

⇜Krishnan Mahadevan⇝

unread,
Jan 14, 2024, 9:22:42 AMJan 14
to testng-users
Folks,

Am sure that all of us at some point in time have wished/wanted that some feature be available in TestNG itself.

On behalf of the TestNG dev team, I am reaching out to ask for any such features that you may want.

If you have any such asks, please add them to this discussion list on GitHub. Feel free to add as much context as possible to it ( code samples or anything else that may add clarity to the feature request )



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/

MCD dotCom

unread,
Jan 14, 2024, 9:19:11 PMJan 14
to testng...@googlegroups.com

Hello,

I would like to invoke the same Java class multiple times within the same XML test tag.

Let's assume I have three Java class files:

FirstTest.java
SecondTest.java
ThirdTest.java
Each file contains a TestNG method. I would like to invoke the FirstTest.java class file twice within the same TestNG method. However, it only runs the FirstTest.java once and skips the second invocation of FirstTest.java.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Demo">
    <test name="Demo test">
         <classes>
             <class name="Demo.FirstTest"/>
             <class name="Demo.SecondTest"/>
             <class name="Demo.ThirdTest"/>
             <!-- Calling the java class file FirstTest again -->
             <class name="Demo.FirstTest"/>
         </classes>
     </test> <!-- Test -->
</suite> <!-- Suite -->


Thank you!




Virus-free.www.avg.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/CANikZLkM06_UHcTBoVL1XmugfSTvYxhqxnvV1U4HuLrZge9U6A%40mail.gmail.com.


--

⇜Krishnan Mahadevan⇝

unread,
Jan 15, 2024, 7:55:15 AMJan 15
to testng...@googlegroups.com
AFAIK, you cannot duplicate the same class multiple times within the same "<test>" tag. If you would like to invoke one or methods within a class multiple times, you should look at leveraging the "invocationCount" attribute of the "@Test" annotation.

Also I would request you to please request for new features in the GitHub Discussion thread that I had shared earlier. That way we have all the new feature asks in one place and it's easier to find and manage discussions around them in one place.

Thanks in advance for your understanding.


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/

MCD dotCom

unread,
Jan 16, 2024, 8:05:31 PMJan 16
to testng...@googlegroups.com

    The invocationCount will not work, as I have to run the tests in the order of the workflow testing requirements. Here is a use case for the workflows that I am testing:

    1. Role A submits an application. (Submit.java)
    2. Role B processes the application. (Process.java)
    3. Role C denies the application. (Deny.java)
    4. Role B processes the application again. (Process.java)

    Note that steps 2 and 4 are performing the same action. Step 4 will only come into play if step 3 results in denial.

    Following XML test suite skips the fourth invocation below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Demo">
    <test name="Demo test">
         <classes>
             <class name="Demo.Submit"/>
             <class name="Demo.Process"/>
             <class name="Demo.Deny"/>
             <!-- Invoking the java class file  Process   again -->
             <class name="Demo.Process"/>

         </classes>
     </test> <!-- Test -->
</suite> <!-- Suite -->  

    If I cannot invoke the same class multiple times within the same XML test tag, considering the above use case, how would you design the test cases?

zaw...@gmail.com

unread,
Jan 17, 2024, 3:52:34 AMJan 17
to testng-users
Hey Krishnan! I would like to see a possibility to invoke a data provider on each test run in case of a test retry. 
I've got a data provider that creates a certain objects via API, and then alters these objects. 
In case of a test retry, created objects might be in invalid state already. 
I would be nice if there was a possibility to have some flag on the data provider annotation that will allow to retry DP on a test retry.

⇜Krishnan Mahadevan⇝

unread,
Jan 17, 2024, 9:25:22 AMJan 17
to testng...@googlegroups.com
@zaworro

I just now updated the documentation related to this.



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/

⇜Krishnan Mahadevan⇝

unread,
Jan 17, 2024, 9:29:41 AMJan 17
to testng...@googlegroups.com

I think there's a discrepancy in the way in which you are trying to build your automation suite. 
If a test class has a test method that represents a particular step in the workflow, then I think you would need to redesign the test class such that you build the following:

  1. You build domain classes that expose utility methods or steps that are part of a particular workflow.
  2. Your test just consumes these utility methods within the domain classes to perform a particular workflow.
If you resort to this approach, then your test classes can just invoke these utility methods in any specific order and you wouldn't be constrained by the need to duplicate a test class multiple times in your suite file to achieve your goal.

If you still have some confusion, I would suggest that you log an issue with the required details and we can take it up from there. 

But IMO, duplicate test classes within the same <test> tag is NOT something that I believe TestNG is going to be supporting. Also I think it would be good if we discuss this specific use case in a GitHub issue rather than in the email list (since there's no way to track the discussion on them)


Thanks & Regard

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/

MCD dotCom

unread,
Jan 17, 2024, 11:56:01 AMJan 17
to testng...@googlegroups.com
@Krishnan

Assuming you meant the following:

// Workflow.java
public class Workflow {
    SubmitUtility submitUtility = new SubmitUtility();
    ProcessUtility processUtility = new ProcessUtility();
    DenyUtility denyUtility = new DenyUtility();

    public void completeWorkflow() {
        submitUtility.submitApplication();
        processUtility.processApplication();
        denyUtility.denyApplication();
        processUtility.processApplication(); // Only if denied
    }
}

// TestWorkflow.java
public class TestWorkflow {
    @Test
    public void testCompleteWorkflow() {
        Workflow workflow = new Workflow();
        workflow.completeWorkflow();
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Demo">
    <test name="Demo test">
        <classes>
            <class name="path.to.TestWorkflow"/>
        </classes>
    </test>
</suite>

I provided you with the simplest workflow scenario. There are times when Role B will process the application days after Role A submits it, Role C will deny the application days after Role B submits it, and so on. All the workflow steps(submit, deny, etc.) will not always be completed in a single run session. Additionally, I need to perform parallel testing using different threads. Managing the workflow via the XML test suites seems much more efficient to me than using the domain classes, where you would have to comment and uncomment particular steps/utility methods. I see drawbacks in both approaches. Thank you!

⇜Krishnan Mahadevan⇝

unread,
Jan 17, 2024, 12:11:05 PMJan 17
to testng...@googlegroups.com
@MCD,

I may not have been able to solve the entire problem statement of your domain, but the intent is to provide you with pointers that can help you re-think your approach.

Here's something that's worth a start.

@FunctionalInterface public interface IWorkFlow { void process(); } public class DenyUtility implements IWorkFlow { @Override public void process() { //Code goes here } } public class ProcessUtility implements IWorkFlow { @Override public void process() { //Code goes here } } public class SubmitUtility implements IWorkFlow { @Override public void process() { //Code goes here } } public class WorkFlowOrchestrator { private final IWorkFlow[] workFlows; //All the individual operations of a workflow would be passed on to the constructor //from within a @BeforeMethod (or) via a data provider (or) within the @Test method itself public WorkFlowOrchestrator(IWorkFlow[] workFlows) { this.workFlows = workFlows; } //This method would be eventually called by your test methods that are validating different //workflows public void completeWorkFlow() { Arrays.stream(workFlows).forEach(IWorkFlow::process); } }

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/

Reply all
Reply to author
Forward
0 new messages