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:
- Create methods for saving/retrieving data with "java.util.concurrent.Locks"
- 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);
}
-
How do you run your tests in parallel?Alexey R.– Alexey R.2020年08月05日 10:09:44 +00:00Commented 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">Millie Anne Volante– Millie Anne Volante2020年08月05日 10:11:28 +00:00Commented 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?Alexey R.– Alexey R.2020年08月05日 11:02:03 +00:00Commented 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.Millie Anne Volante– Millie Anne Volante2020年08月06日 03:12:10 +00:00Commented Aug 6, 2020 at 3:12