From a2f02dbfc04d5d7463612848067bdde26c84b743 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 6 Mar 2022 17:51:49 +0100 Subject: [PATCH] Improve documentation for TestContext events This commit improves the documentation for test execution events, especially with regard to the fact that, by default, a BeforeTestClassEvent is not published for the first test class using a particular ApplicationContext. This commit also introduces tests that verify the default behavior and the ability to change the default behavior with a custom TestExecutionListener that eagerly loads the context. Closes gh-27757 --- .../EventPublishingTestExecutionListener.java | 42 ++-- .../event/annotation/AfterTestClass.java | 4 +- .../event/annotation/AfterTestExecution.java | 4 +- .../event/annotation/AfterTestMethod.java | 4 +- .../event/annotation/BeforeTestClass.java | 4 +- .../event/annotation/BeforeTestExecution.java | 4 +- .../event/annotation/BeforeTestMethod.java | 4 +- .../event/annotation/PrepareTestInstance.java | 4 +- .../event/annotation/package-info.java | 2 +- ...agerTestExecutionEventPublishingTests.java | 190 ++++++++++++++++++ src/docs/asciidoc/testing.adoc | 24 ++- 11 files changed, 264 insertions(+), 22 deletions(-) create mode 100644 spring-test/src/test/java/org/springframework/test/context/event/EagerTestExecutionEventPublishingTests.java diff --git a/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java index d25af05b3d38..d6b5c9cef4f3 100644 --- a/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,16 +17,12 @@ package org.springframework.test.context.event; import org.springframework.test.context.TestContext; -import org.springframework.test.context.TestExecutionListener; import org.springframework.test.context.support.AbstractTestExecutionListener; /** - * {@link org.springframework.test.context.TestExecutionListener TestExecutionListener} - * that publishes test execution events to the + * {@code TestExecutionListener} that publishes test execution events to the * {@link org.springframework.context.ApplicationContext ApplicationContext} - * for the currently executing test. Events are only published if the - * {@code ApplicationContext} {@linkplain TestContext#hasApplicationContext() - * has already been loaded}. + * for the currently executing test. * *

Supported Events

*