In this lesson, we'll discover the second test instance configuration provided by JUnit Jupiter. When the
@TestInstance annotation is set to
PER_CLASS, only one instance is created of a test class, and each test is executed on that single object. This change is demonstrated by looking at the value of the
this variable inside multiple test methods.
Furthermore, we'll configure our projects to use a particular "test instance mode" globally: Through the Gradle build files, as well as through the IDE. After applying the global configuration, only a single instance is used per class, even without explicitly setting this value through the annotation.
- Only 1 test instance is created when using
junit.jupiter.testinstance.lifecycle.defaultsystem property controls the global setting across the entire codebase
- Java & Android projects allow this configuration through Gradle & the IDE