Commit Graph

37 Commits

Author SHA1 Message Date
Sam Brannen 617ba84577 Remove notes about WebTestClient type inference issue in Kotlin
Since gh-28144 was resolved in Spring Framework 6.0, these notes are no
longer relevant.
2023-11-21 10:23:10 +01:00
Sam Brannen 8a7144ba42 Document how to log @⁠Sql scripts and statements
Closes gh-31589
2023-11-10 11:19:38 +01:00
Sam Brannen 6c3a3dc7d9 Polishing 2023-11-10 11:18:26 +01:00
Sam Brannen b1a7161218 Document @⁠Sql class-level execution phase support in the reference manual
Closes gh-31377
2023-11-09 15:22:14 +01:00
Sam Brannen 332de60586 Update @⁠Sql docs regarding Kotlin and Java 8 2023-11-09 15:19:52 +01:00
Sam Brannen 55d13a0232 Document @⁠DisabledInAotMode & @[Enabled|Disabled]InNativeImage in ref docs
Closes gh-31437
Closes gh-31438
2023-11-08 16:22:35 +01:00
Sam Brannen a220c545fc Support declarative ContextCustomizerFactory registration in the TCF
Prior to this commit, it was only possible to register a
ContextCustomizerFactory in the TestContext framework (TCF) via the
SpringFactoriesLoader mechanism.

This commit introduces support for declarative registration of a
ContextCustomizerFactory local to a test class via a new
@ContextCustomizerFactories annotation.

Closes gh-26148
2023-09-13 19:59:50 +02:00
Sam Brannen 99a50e7cea Polishing 2023-09-13 19:52:17 +02:00
Sam Brannen a678be80ea Merge branch '6.0.x' 2023-09-13 17:51:02 +02:00
Sam Brannen f5f8eab405 Remove duplicated section links for test annotations
Since the auto-generated "Section Summary" includes the exact same
links, there's no need to manually duplicate them.
2023-09-13 17:50:12 +02:00
Sam Brannen 345910591a Polishing 2023-09-12 15:08:11 +02:00
Sam Brannen ed83461021 Support parameter injection in @[Before|After]Transaction methods
Prior to this commit, @​BeforeTransaction and @​AfterTransaction
methods could not accept any arguments. This is acceptable with testing
frameworks such as JUnit 4 and TestNG that do not provide support for
parameter injection. However, users of JUnit Jupiter have become
accustomed to being able to accept arguments in lifecycle methods
annotated with JUnit's @​BeforeEach, @​AfterEach, etc.

As a follow up to the previous commit (see gh-31199), this commit
introduces first-class support for parameter injection in
@​BeforeTransaction and @​AfterTransaction methods, as demonstrated in
the following example.

@​BeforeTransaction
void verifyInitialDatabaseState(@Autowired DataSource dataSource) {
	// Use the DataSource to verify the initial DB state
}

Closes gh-30736
2023-09-10 20:15:26 +02:00
Sam Brannen 0ebdd8cb98 Polishing 2023-09-10 20:15:04 +02:00
Sam Brannen dfea3d05aa Revise support for JSR-330 and Jakarta @Inject for autowiring test constructors
Closes gh-29851
2023-09-08 19:29:28 +02:00
Sam Brannen 279e6eb423 Document best practices for inlined properties in @TestPropertySource 2023-08-16 17:27:18 +02:00
Sam Brannen 1f544f113a Support resource patterns in @TestPropertySource locations
Inspired by the recently added support for resource patterns in
@PropertySource locations, this commit adds the same support for
resource locations in @TestPropertySource.

For example, assuming the `config` folder in the classpath contains
only 3 files matching the pattern `file?.properties`,

... the following:

@TestPropertySource("classpath:/config/file1.properties")
@TestPropertySource("classpath:/config/file2.properties")
@TestPropertySource("classpath:/config/file3.properties")

... or:

@TestPropertySource({
    "classpath:/config/file1.properties",
    "classpath:/config/file2.properties",
    "classpath:/config/file3.properties"
})

... can now be replaced by:

@TestPropertySource("classpath*:/config/file?.properties")

See gh-21325
Closes gh-31055
2023-08-16 12:34:20 +02:00
Sam Brannen 3a38bb48b5 Polishing 2023-08-16 12:17:58 +02:00
Sam Brannen d890827bae Fisk asterisk formatting in Asciidoc 2023-08-04 15:41:39 +03:00
Sam Brannen 04cce0bafd Support custom properties file formats in @TestPropertySource
Spring Framework 4.3 introduced the `PropertySourceFactory` SPI for use
with `@PropertySource` on `@Configuration` classes; however, prior to
this commit there was no mechanism to support custom properties file
formats in `@TestPropertySource` for integration tests.

This commit introduces support for configuring a custom
`PropertySourceFactory` via a new `factory` attribute in
`@TestPropertySource` in order to support custom file formats such as
JSON, YAML, etc.

For example, if you create a YamlPropertySourceFactory, you can use it
in integration tests as follows.

@SpringJUnitConfig
@TestPropertySource(locations = "/test.yaml", factory = YamlPropertySourceFactory.class)
class MyTestClass { /* ... /* }

If a custom factory is not specified, traditional `*.properties` and
`*.xml` based `java.util.Properties` file formats are supported, which
was the existing behavior.

Closes gh-30981
2023-08-04 14:57:22 +03:00
Sam Brannen 34747baed0 Fix broken links to AOT sections 2023-08-03 11:27:16 +03:00
Sam Brannen 961084dfe0 Merge branch '6.0.x' 2023-08-03 11:27:37 +03:00
Sam Brannen 3e5aa8d734 Fail on error by default during test AOT processing
Prior to this commit, if an error was encountered during build-time AOT
processing, the error was logged at WARN/DEBUG level, and processing
continued.

With this commit, test AOT processing now fails on error by default. In
addition, the `failOnError` mode can be disabled by setting the
`spring.test.aot.processing.failOnError` Spring/System property to
`false`.

Closes gh-30977
2023-08-03 10:59:46 +03:00
Sam Brannen f12d81f791 Merge branch '6.0.x' 2023-06-22 11:36:10 +02:00
Anton Gubenko 9b5cbc1334 Fix link text from "null" to "Component Classes" in Testing chapter
Closes gh-30714
2023-06-22 11:35:23 +02:00
Sam Brannen 53828cbfad Merge branch '6.0.x' 2023-06-14 14:39:06 +02:00
Sam Brannen aa2028127f Overhaul TestExecutionListener for Micrometer ObservationRegistry
This commit overhauls the TestExecutionListener for Micrometer's
ObservationRegistry that was introduced in the previous commit.

Specifically, this commit:

- Renames the listener to MicrometerObservationRegistryTestExecutionListener
  since the use of a ThreadLocal is an implementation detail that may
  change over time.

- Makes the listener package-private instead of public in order to
  allow the team greater flexibility in evolving this feature.

- Eagerly loads the ObservationThreadLocalAccessor class and verifies
  that it has a getObservationRegistry() method to ensure that the
  listener is properly skipped when SpringFactoriesLoader attempts to
  load it, if Micrometer 1.10.8+ is not on the classpath.

- Switches the listener's automatic registration order to 2500 in order
  to register it after the DependencyInjectionTestExecutionListener.

- Only tracks the previous ObservationRegistry in beforeTestMethod() if
  the test's ApplicationContext contains an ObservationRegistry bean.

- Properly removes the TestContext attribute for the previous
  ObservationRegistry in afterTestMethod().

- Introduces DEBUG logging for diagnostics.

- Adds an entry in the Javadoc for TestExecutionListener as well as in
  the Testing chapter in the reference manual.

Closes gh-30658
2023-06-14 14:36:05 +02:00
Sam Brannen bff81d3056 Document test context failure threshold support in reference manual
See gh-14182
2023-06-09 17:45:12 +02:00
Sam Brannen d7d0292654 Document @DirtiesContext semantics when declared at class & method level
Closes gh-30623
2023-06-09 11:49:15 +02:00
Rob Winch 3a0a19cff8 Fix migration to asciidoctor tabs
The automation to asciidoctor tabs did not migrate properly for all
cases this commit fixes the migration.

See gh-30435
2023-05-09 12:15:43 +01:00
Rob Winch 39146f9066 Migrate to Asciidoctor Tabs 2023-05-04 15:35:05 +01:00
Rob Winch 3774e9be7a Trim IDs with parent 2023-05-04 15:35:05 +01:00
Rob Winch 35229c8bff Enable Section Summary TOC for small pages 2023-05-04 15:35:05 +01:00
Rob Winch 139cde47e2 Fix cross references 2023-05-04 15:35:05 +01:00
Rob Winch 6b341ddf19 Remove includes 2023-05-04 15:35:05 +01:00
Rob Winch 9f49d24833 Split files 2023-05-04 15:35:05 +01:00
Rob Winch 9ceb75b228 Insert explicit ids for headers 2023-05-04 15:35:05 +01:00
Rob Winch 3fe7c65218 Migrate Structure 2023-05-04 15:35:05 +01:00