|
28 | 28 | import org.junit.jupiter.api.extension.ParameterResolutionException;
|
29 | 29 |
|
30 | 30 | /**
|
31 |
| - * {@code @TempDir} can be used to annotate a field in a test class or a |
32 |
| - * parameter in a lifecycle method or test method of type {@link Path} or |
33 |
| - * {@link File} that should be resolved into a temporary directory. |
34 |
| - * |
35 |
| - * <p>Please note that {@code @TempDir} is not supported on constructor |
36 |
| - * parameters. Please use field injection instead by annotating an instance |
37 |
| - * field with {@code @TempDir}. |
| 31 | + * {@code @TempDir} can be used to annotate a field in a test class or a parameter |
| 32 | + * in a test class constructor, lifecycle method, or test method of type |
| 33 | + * {@link Path} or {@link File} that should be resolved into a temporary directory. |
38 | 34 | *
|
39 | 35 | * <h2>Creation</h2>
|
40 | 36 | *
|
41 | 37 | * <p>The temporary directory is only created if a field in a test class or a
|
42 |
| - * parameter in a lifecycle method or test method is annotated with |
43 |
| - * {@code @TempDir}. |
44 |
| - * An {@link ExtensionConfigurationException} or a |
45 |
| - * {@link ParameterResolutionException} will be thrown in one of the following |
| 38 | + * parameter in a test class constructor, lifecycle method, or test method is |
| 39 | + * annotated with {@code @TempDir}. An {@link ExtensionConfigurationException} or |
| 40 | + * a {@link ParameterResolutionException} will be thrown in one of the following |
46 | 41 | * cases:
|
47 | 42 | *
|
48 | 43 | * <ul>
|
|
56 | 51 | * </li>
|
57 | 52 | * </ul>
|
58 | 53 | *
|
59 |
| - * In addition, a {@code ParameterResolutionException} will be thrown for a |
60 |
| - * constructor parameter annotated with {@code @TempDir}. |
61 |
| - * |
62 | 54 | * <h2>Scope</h2>
|
63 | 55 | *
|
64 |
| - * <p>By default, a separate temporary directory is created for every |
65 |
| - * declaration of the {@code @TempDir} annotation. If you want to share a |
66 |
| - * temporary directory across all tests in a test class, you should declare the |
67 |
| - * annotation on a {@code static} field or on a parameter of a |
| 56 | + * <p>By default, a separate temporary directory is created for every declaration |
| 57 | + * of the {@code @TempDir} annotation. For better isolation when using |
| 58 | + * {@link org.junit.jupiter.api.TestInstance.Lifecycle#PER_METHOD @TestInstance(Lifecycle.PER_METHOD)} |
| 59 | + * semantics, you can annotate an instance field or a parameter in the test class |
| 60 | + * constructor with {@code @TempDir} so that each test method uses a separate |
| 61 | + * temporary directory. Alternatively, if you want to share a temporary directory |
| 62 | + * across all tests in a test class, you should declare the annotation on a |
| 63 | + * {@code static} field or on a parameter of a |
68 | 64 | * {@link org.junit.jupiter.api.BeforeAll @BeforeAll} method.
|
69 | 65 | *
|
70 | 66 | * <h3>Old behavior</h3>
|
|
0 commit comments