Saturday, November 7, 2020

JUnit initialization failures are reported like test methods

One of my Gradle plugins processes JUnit results XML files and needs to examine the method in the class file corresponding to each test case. Loading the class and searching for the method specified in the XML usually worked fine, but recently I found out about a crash when looking for the method. Apparently if JUnit 4 is unable to initialize a test class (e.g. the static initializer fails or tests are improperly declared), it still emits a results file with failure information recorded in a test case named classMethod or initializationError. Nothing else seems to distinguish them from real test methods, so my plugin tried and failed to find a method with that name. I adjusted the plugin to watch for those names specifically - providing a useful notice - and gracefully ignore other unknown methods.

No comments:

Post a Comment