Issue
Is there a way to determine the count of assertions called in tests? I am using the JUnit 5 Platform Launcher and can count PASSes, FAILs in each Test Identifier, but cannot count assertions. This is important in results analytics and reporting since not every test is of the same "density," not by a long shot.
I can provide a wrapper around each assert that increments a count or store a hard-coded sum in a test annotation, but the former introduces a contract that must be upheld just for a simple hack in JUnit 5 or can be ignored and the latter involves a lot of manual counting. Appreciated.
import static org.junit.jupiter.api.Assertions.assertEquals;
...
int index = 0;
while (index < testValueCount){
assertTrue(testValue[index]>0); // Want to capture testValueCount assertions here, not 1 (or none)
++index;
}
Solution
No, that is unfortunately not possible.
Neither the JUnit Platform nor JUnit Jupiter provides a way to track the number of assertions performed.
If you truly need such a feature, you will either need to wrap assertion invocations on your own or find an assertion framework that supports invocation tracking.
Answered By - Sam Brannen
Answer Checked By - Terry (JavaFixing Volunteer)