junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/AfterTestExecutionCallback.java
raw symbols SCIP| 1 | /* |
| 2 | * Copyright 2015-2024 the original author or authors. |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | * accompanies this distribution and is available at |
| 7 | * |
| 8 | * https://www.eclipse.org/legal/epl-v20.html |
| 9 | */ |
| 10 | |
| 11 | package org.junit.jupiter.api.extension; |
| 12 | |
| 13 | import static org.apiguardian.api.API.Status.STABLE; |
| 14 | |
| 15 | import org.apiguardian.api.API; |
| 16 | |
| 17 | /** |
| 18 | * {@code AfterTestExecutionCallback} defines the API for {@link Extension |
| 19 | * Extensions} that wish to provide additional behavior to tests |
| 20 | * <strong>immediately</strong> after an individual test has been executed but |
| 21 | * before any user-defined teardown methods (e.g., |
| 22 | * {@link org.junit.jupiter.api.AfterEach @AfterEach} methods) have been executed |
| 23 | * for that test. |
| 24 | * |
| 25 | * <p>Concrete implementations often implement {@link BeforeTestExecutionCallback} |
| 26 | * as well. If you wish to have your callbacks <em>wrapped</em> around user-defined |
| 27 | * setup and teardown methods, implement {@link BeforeEachCallback} and |
| 28 | * {@link AfterEachCallback} instead of {@link BeforeTestExecutionCallback} and |
| 29 | * {@link AfterTestExecutionCallback}. |
| 30 | * |
| 31 | * <h2>Constructor Requirements</h2> |
| 32 | * |
| 33 | * <p>Consult the documentation in {@link Extension} for details on |
| 34 | * constructor requirements. |
| 35 | * |
| 36 | * <h2>Wrapping Behavior</h2> |
| 37 | * |
| 38 | * <p>JUnit Jupiter guarantees <em>wrapping behavior</em> for multiple |
| 39 | * registered extensions that implement lifecycle callbacks such as |
| 40 | * {@link BeforeAllCallback}, {@link AfterAllCallback}, |
| 41 | * {@link BeforeEachCallback}, {@link AfterEachCallback}, |
| 42 | * {@link BeforeTestExecutionCallback}, and {@link AfterTestExecutionCallback}. |
| 43 | * |
| 44 | * <p>That means that, given two extensions {@code Extension1} and |
| 45 | * {@code Extension2} with {@code Extension1} registered before |
| 46 | * {@code Extension2}, any "before" callbacks implemented by {@code Extension1} |
| 47 | * are guaranteed to execute before any "before" callbacks implemented by |
| 48 | * {@code Extension2}. Similarly, given the two same two extensions registered |
| 49 | * in the same order, any "after" callbacks implemented by {@code Extension1} |
| 50 | * are guaranteed to execute after any "after" callbacks implemented by |
| 51 | * {@code Extension2}. {@code Extension1} is therefore said to <em>wrap</em> |
| 52 | * {@code Extension2}. |
| 53 | * |
| 54 | * @since 5.0 |
| 55 | * @see org.junit.jupiter.api.Test |
| 56 | * @see BeforeTestExecutionCallback |
| 57 | * @see BeforeEachCallback |
| 58 | * @see AfterEachCallback |
| 59 | * @see BeforeAllCallback |
| 60 | * @see AfterAllCallback |
| 61 | */ |
| 62 | @FunctionalInterface |
| 63 | @API(status = STABLE, since = "5.0") |
| 64 | public interface AfterTestExecutionCallback extends Extension { |
| 65 | |
| 66 | /** |
| 67 | * Callback that is invoked <em>immediately after</em> an individual test has |
| 68 | * been executed but before any user-defined teardown methods have been |
| 69 | * executed for that test. |
| 70 | * |
| 71 | * @param context the current extension context; never {@code null} |
| 72 | */ |
| 73 | void afterTestExecution(ExtensionContext context) throws Exception; |
| 74 | |
| 75 | } |