Search code examples
seleniumtestingautomationtestngbrowser-automation

Is there a way to flush or reuse SoftAssert


I understand that in every @Test method, I should use a new instance of SoftAssert.

However, is there any way to flush or reuse the already existing one? Or how do I free up memory after every test case?

If I have 1000 test cases, isn't creating 1000 instances of SoftAssert inefficient? Also, it is possible that when the system is executing 1000th test case, 999 instances of SoftAssert will be sitting in the memory doing nothing, correct?

So in essence, what is the best way to use SoftAssert?


Solution

  • Take a look at this question Java Object Reuse.

    I think when you talk about 1000 instances, you should not care about this.

    Also, SoftAssert seems not designed to be reusable, there are no clear/flush methods

    https://javadoc.io/doc/org.testng/testng/latest/org/testng/asserts/SoftAssert.html.