Test Class (Test)

ARCHITECTURAL Role

This pattern is unrestricted; it is used within any architectural layer.

BEHAVIOR DEFINED

A PED Test Class (Test) seeks to blend the best outcomes of traditional ‘in-container’ and ‘outside-the-container’ approaches.  That is, functionally equivalent services (e.g. in-memory database/RESTful container/CDI container etc.) are lazily launched within the JUnit JVM using  Test Rules. We call this approach the  JUnit Strategy for Testing and demonstrate it with the open source Justify framework. 

Structural Characteristics

Characteristic

Recommended

Note

 Extend Base Class N Avoid Runners Also  
 No-arg Constructor Y  
 CDI Scoping N/A  
 Instance State Optional  
 Static Public Methods (enum) N  
 Fluent Methods N  
 Delegate to Rule/Helper/Populator Y 1.
 Worker-thread Safe N/A  
  1. A Rule enables reusable configuration logic. An assertion class enables reusable assertion logic. A populator enables reusable database load logic. 
Source Example