--
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+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
Class Util{ static void createchart(SoftAssert sa, String parameter1){ //chart is created verifyLabels(sa); verifyTooltips(sa); } static void verifyLabels(SoftAssert sa){ sa.AssertTrue("actual","expected","message");
}}
Class PieChart{
@Test public void makePieChart(){
SoftAssert sa = new SoftAssert(); Util.createchart(sa, "comapny"); Util.createchart(sa, "year"); sa.assertAll(); }}
public class AssertsListener implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
Asserts.clear();
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
try {
Asserts.assertAll();
} catch (AssertionError ae) {
Throwable error = testResult.getThrowable();
if (error == null)
testResult.setThrowable(ae);
else
testResult.setThrowable(new RuntimeException(
String.format("%s. \nOther errors: %s", error, ae)));
if (error instanceof SkipException)
testResult.setStatus(ITestResult.SKIP);
else
testResult.setStatus(ITestResult.FAILURE);
}
}
}
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
class Asserts {
private final static ThreadLocal<SoftAssert> SA_CONTAINER =
new ThreadLocal<>();
public static void clear() { SA_CONTAINER.set(new SoftAssert());}
public static SoftAssert save() { return SA_CONTAINER.get();}
public static void assertAll() {
try {
SA_CONTAINER.get().assertAll();
} finally {
clear();
}
}
}
@Listeners(AssertsListener.class)
public class MyTests {
@Test()
void myTest() {
Asserts.clear(); // optional with AssertsListener
String actual = "222";
Asserts.save().assertEquals(actual, "111");
Asserts.save().assertEquals(actual, "222");
Asserts.save().assertEquals(actual, "333");
//Asserts.assertAll(); // optional with AssertsListener
}
}