Test Rule (Rule)

ARCHITECTURAL Role

This pattern is unrestricted; it is used for testing any architectural layer.

BEHAVIOR DEFINED

A PED Test Rule (Rule) implements the JUnit TestRule Interface and provides a consistent semantic for pre/post configuration of tests. The Rule approach is preferred over base classes and Runners for much same reason; multiple rules can be active concurrently.

The JUST approach benefits from a focused use of  the JUnit @Rule annotation. The open source Justify testing framework demonstrates real-world  fluency, velocity and flexibility.

Structural Characteristics

Characteristic

Recommended

Note

 Extend Base Class Y  
 No-arg Constructor N  
 Protected Constructor Y Supports Fluent Methods
 CDI Scoping N/A  
 Instance State Optional  
 Static Public Methods (enum) Y 1. 
 Fluent Methods Y  
 Delegate to Helper Optional  
 Worker-thread Safe N/A  
  1. There are situations where extending this class may be advantageous, therefore we recommend that an enum is NOT used.
Source Example