Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/BeforeEachCallback.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 BeforeEachCallback} defines the API for {@link Extension Extensions}
19 * that wish to provide additional behavior to tests before an individual test
20 * and any user-defined setup methods (e.g.,
21 * {@link org.junit.jupiter.api.BeforeEach @BeforeEach} methods) for that test
22 * have been executed.
23 *
24 * <p>Concrete implementations often implement {@link AfterEachCallback} as well.
25 * If you do not wish to have your callbacks <em>wrapped</em> around user-defined
26 * setup and teardown methods, implement {@link BeforeTestExecutionCallback} and
27 * {@link AfterTestExecutionCallback} instead of {@link BeforeEachCallback} and
28 * {@link AfterEachCallback}.
29 *
30 * <h2>Constructor Requirements</h2>
31 *
32 * <p>Consult the documentation in {@link Extension} for details on
33 * constructor requirements.
34 *
35 * <h2>Wrapping Behavior</h2>
36 *
37 * <p>JUnit Jupiter guarantees <em>wrapping behavior</em> for multiple
38 * registered extensions that implement lifecycle callbacks such as
39 * {@link BeforeAllCallback}, {@link AfterAllCallback},
40 * {@link BeforeEachCallback}, {@link AfterEachCallback},
41 * {@link BeforeTestExecutionCallback}, and {@link AfterTestExecutionCallback}.
42 *
43 * <p>That means that, given two extensions {@code Extension1} and
44 * {@code Extension2} with {@code Extension1} registered before
45 * {@code Extension2}, any "before" callbacks implemented by {@code Extension1}
46 * are guaranteed to execute before any "before" callbacks implemented by
47 * {@code Extension2}. Similarly, given the two same two extensions registered
48 * in the same order, any "after" callbacks implemented by {@code Extension1}
49 * are guaranteed to execute after any "after" callbacks implemented by
50 * {@code Extension2}. {@code Extension1} is therefore said to <em>wrap</em>
51 * {@code Extension2}.
52 *
53 * @since 5.0
54 * @see org.junit.jupiter.api.BeforeEach
55 * @see AfterEachCallback
56 * @see BeforeTestExecutionCallback
57 * @see AfterTestExecutionCallback
58 * @see BeforeAllCallback
59 * @see AfterAllCallback
60 */
61 @FunctionalInterface
62 @API(status = STABLE, since = "5.0")
63 public interface BeforeEachCallback extends Extension {
64
65 /**
66 * Callback that is invoked <em>before</em> an individual test and any
67 * user-defined setup methods for that test have been executed.
68 *
69 * @param context the current extension context; never {@code null}
70 */
71 void beforeEach(ExtensionContext context) throws Exception;
72
73 }