Question even if the assert fails the execution should carry on

PRoshan

New member
Joined
Jun 26, 2020
Messages
3
Programming Experience
1-3
I want a design pattern which could help me resolve the problem that even if one of the assert statement fails in the test case the rest should work.

I know people would say write individual test cases, but its integration testing I want to use the unique id generated in the first step for rest of the test cases. I came across Page Object Model Pattern, but the issue there is if one assert fails the entire execution will fail or stop...

Could someone help with it? Atleast if someone could suggest a better design pattern or approach.
 
The point of Assert methods is generally that they throw an exception if the specific condition they are testing is not met. As is always the case, you would need to either catch that exception or ensure that it's not thrown in the first place.
 
Yeah but I want that even if it fails at any point the execution should continue and give me the results of all assertions at the last
 
In that case, don't use your testing framework's assertion classes raw. Instead roll your own assertion class that logs failed assertions into a list of failed assertions. And at the end of your test, assert that the list is not empty using the testing framework's assertion class. For the message of that assertion, you could use String.Join() to build a long string with the logged messages.

I believe that xUnit has something like this built in, but I have only seen it in passing while I was searching for something else. I was searching for asserting that an exception gets thrown, but it had to be from a set of exceptions, but there was no common base class among them except for the base Exception class. I did not want that base class. I saw an approach suggested by one of the original xUnit authors, but I ended up re-writing my tests because in the end, I wanted to really test that a particular set of pre-conditions and actions would lead to a specific exception, rather than my original approach if just doing on fixed set should throw some kind of exception.)
 
Back
Top Bottom