Skip to content

Add test lifecycle events for theory method permutations

Choose a tag to compare

@sbabcoc sbabcoc released this 26 Nov 04:21
· 138 commits to master since this release

This release expands on Theories runner support, adding test lifecycle event notifications for Theory method permutations. Without JUnit Foundation, these notifications are entirely absent - including AssumptionViolatedException events, which reveal data points that were rejected by @Theory methods as inapplicable.

Several chunks of code-generation magic were required to add these permutation events:

  • The methodBlock method is intercepted. For theory methods, the actual class runner statement is stored and a "lifecycle catalyst" statement is returned instead. This enables the interceptor declared in the RunWithCompleteAssignment class to manage the execution of the actual statement.
  • The runWithCompleteAssignment method is intercepted. The "lifecycle catalyst" created by the MethodBlock class attaches the class runner to the thread and creates a new atomic test for the target method. The actual method block statement is retrieved from MethodBlock and executed, publishing a complete set of test lifecycle events.
  • The describeChild method is intercepted. For theory permutations, a unique ID is generated from the method name and arguments. This unique ID is injected into the description, allowing it to be used as a distinct "key" throughout the method lifecycle.
  • Tracking was added to the run method interceptor to retain a mapping of parent runners to the notifiers that were provided to them.
  • Tracking was added to the RunAnnouncer listener to retain a mapping of method descriptions to their corresponding atomic test objects.

This release also includes various other theory-related revisions and optimizations of existing implementation. Share and enjoy!