3

This question is similar to How to manage application data when running multiple tests in parallel?

But I want to know if there's a way or listener in testNG that will lock certain method when running tests in parallel.

What I tried was:

  1. Create methods for saving/retrieving data with "java.util.concurrent.Locks"
  2. Add those methods in "beforeInitialize" listener

However, the test instance happens before "beforeInitialize". In short, there's still possibility that it access those methods(with lock) at the same time, using different instance.

Edit (1) : Added sample code I used to log and retrieve used data

 public static List<String> unitsReturned(){
 String listStr = getProperty("UNITS_RETURNED");
 if(listStr.equals("UNITS_RETURNED"))
 return new ArrayList<>();
 return textFormatter.getListfromStringDelimiterNonTrimmed(listStr, ",");
 }
 
 public static void logUnitReturned(String unitName) {
 String listStr = getProperty("UNITS_RETURNED");
 if(listStr.equals("UNITS_RETURNED"))
 setProperty("UNITS_RETURNED", unitName);
 else
 setProperty("UNITS_RETURNED", getProperty("UNITS_RETURNED")+","+unitName);
 }
asked Aug 5, 2020 at 10:05
4
  • How do you run your tests in parallel? Commented Aug 5, 2020 at 10:09
  • like this:<!DOCTYPE suite SYSTEM "testng.org/testng-1.0.dtd"> <suite name="APP Tests Suite" verbose="0" parallel="true" preserve-order="true"> Commented Aug 5, 2020 at 10:11
  • Can you show your code? Why aren't you just use data providers which provide the objects for each particular test separately? Commented Aug 5, 2020 at 11:02
  • @AlexeyR. , the data to be used is dependent on available data in the app. For e.g. there's 5 different customers. I want my suite to take each customer then perform different tests. Like for customer 1, will delete ; customer 2, will update ..and so on. Commented Aug 6, 2020 at 3:12

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.