I know this question is pretty old. But I came here searching for an answer and I formulated the answer myself. Hope this answer helps someone else. SoftAssertion can be abstracted to the BaseClass in the following way using ThreadLocal variable,
public class BaseTest {
ThreadLocal<SoftAssert> softAssert = new ThreadLocal<SoftAssert>();
@BeforeMethod
public void initialise() {
softAssert.set(new SoftAssert());
}
}
public class AppTest extends BaseTest{
@Test(alwaysRun = true)
public void test1() throws Exception {
softAssert.get().fail("test1() I got failed - Test1");
softAssert.get().fail("test1() I got failed - Test1");
softAssert.get().assertAll();
}
@Test(alwaysRun = true)
public void test2() {
softAssert.get().fail("test2 I got failed - Test2");
softAssert.get().fail("test2 I got failed - Test2");
softAssert.get().assertAll();
}
}
**
Output:
Test1 output:
java.lang.AssertionError: The following asserts failed:
test1() I got failed - Test1,
test1() I got failed - Test1
Test2 Output:
java.lang.AssertionError: The following asserts failed:
test2 I got failed - Test2,
test2 I got failed - Test2
**