Skip to content

Commit ca6a321

Browse files
committed
Pull the whole "Testing" documentation section up to the top level
Closes gh-38361
1 parent 00a10fd commit ca6a321

File tree

106 files changed

+622
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+622
-627
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc

+54-54
Large diffs are not rendered by default.

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/tracing.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ For the example above, setting this property to `baggage1` results in an MDC ent
218218
== Tests
219219

220220
Tracing components which are reporting data are not auto-configured when using `@SpringBootTest`.
221-
See xref:features/testing.adoc#features.testing.spring-boot-applications.tracing[the testing section] for more details.
221+
See xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.tracing[the testing section] for more details.

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/dev-services.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ spring:
286286
[[features.dev-services.testcontainers]]
287287
== Testcontainers Support
288288

289-
As well as xref:features/testing.adoc#features.testing.testcontainers[using Testcontainers for integration testing], it's also possible to use them at development time.
289+
As well as xref:testing/testcontainers.adoc#testing.testcontainers[using Testcontainers for integration testing], it's also possible to use them at development time.
290290
The next sections will provide more details about that.
291291

292292

@@ -312,7 +312,7 @@ To do this, you need to make sure that the `spring-boot-testcontainers` module h
312312
Once that has been done, you can create a `@TestConfiguration` class that declares `@Bean` methods for the containers you want to start.
313313

314314
You can also annotate your `@Bean` methods with `@ServiceConnection` in order to create `ConnectionDetails` beans.
315-
See xref:features/testing.adoc#features.testing.testcontainers.service-connections[the service connections] section for details of the supported technologies.
315+
See xref:testing/testcontainers.adoc#testing.testcontainers.service-connections[the service connections] section for details of the supported technologies.
316316

317317
A typical Testcontainers configuration would look like this:
318318

@@ -338,7 +338,7 @@ TIP: You can use the Maven goal `spring-boot:test-run` or the Gradle task `bootT
338338
==== Contributing Dynamic Properties at Development Time
339339

340340
If you want to contribute dynamic properties at development time from your `Container` `@Bean` methods, you can do so by injecting a `DynamicPropertyRegistry`.
341-
This works in a similar way to the xref:features/testing.adoc#features.testing.testcontainers.dynamic-properties[`@DynamicPropertySource` annotation] that you can use in your tests.
341+
This works in a similar way to the xref:testing/testcontainers.adoc#testing.testcontainers.dynamic-properties[`@DynamicPropertySource` annotation] that you can use in your tests.
342342
It allows you to add properties that will become available once your container has started.
343343

344344
A typical configuration would look like this:
@@ -365,7 +365,7 @@ To do so, add the `@ImportTestcontainers` annotation to your test configuration
365365

366366
include-code::MyContainersConfiguration[]
367367

368-
TIP: If you don't intend to use the xref:features/testing.adoc#features.testing.testcontainers.service-connections[service connections feature] but want to use xref:features/testing.adoc#features.testing.testcontainers.dynamic-properties[`@DynamicPropertySource`] instead, remove the `@ServiceConnection` annotation from the `Container` fields.
368+
TIP: If you don't intend to use the xref:testing/testcontainers.adoc#testing.testcontainers.service-connections[service connections feature] but want to use xref:testing/testcontainers.adoc#testing.testcontainers.dynamic-properties[`@DynamicPropertySource`] instead, remove the `@ServiceConnection` annotation from the `Container` fields.
369369
You can also add `@DynamicPropertySource` annotated methods to your declaration class.
370370

371371

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Sources are considered in the following order:
2424
. Properties from `SPRING_APPLICATION_JSON` (inline JSON embedded in an environment variable or system property).
2525
. Command line arguments.
2626
. `properties` attribute on your tests.
27-
Available on xref:api:java/org/springframework/boot/test/context/SpringBootTest.html[`@SpringBootTest`] and the xref:features/testing.adoc#features.testing.spring-boot-applications.autoconfigured-tests[test annotations for testing a particular slice of your application].
27+
Available on xref:api:java/org/springframework/boot/test/context/SpringBootTest.html[`@SpringBootTest`] and the xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[test annotations for testing a particular slice of your application].
2828
. {url-spring-framework-javadoc}/org/springframework/test/context/DynamicPropertySource.html[`@DynamicPropertySource`] annotations in your tests.
2929
. {url-spring-framework-javadoc}/org/springframework/test/context/TestPropertySource.html[`@TestPropertySource`] annotations on your tests.
3030
. xref:using/devtools.adoc#using.devtools.globalsettings[Devtools global settings properties] in the `$HOME/.config/spring-boot` directory when devtools is active.

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ JUnit 5 enables a test class to be instantiated once and reused for all of the c
145145
This makes it possible to use `@BeforeAll` and `@AfterAll` annotations on non-static methods, which is a good fit for Kotlin.
146146

147147
To mock Kotlin classes, https://mockk.io/[MockK] is recommended.
148-
If you need the `MockK` equivalent of the Mockito specific xref:features/testing.adoc#features.testing.spring-boot-applications.mocking-beans[`@MockBean` and `@SpyBean` annotations], you can use https://github.com/Ninja-Squad/springmockk[SpringMockK] which provides similar `@MockkBean` and `@SpykBean` annotations.
148+
If you need the `MockK` equivalent of the Mockito specific xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.mocking-beans[`@MockBean` and `@SpyBean` annotations], you can use https://github.com/Ninja-Squad/springmockk[SpringMockK] which provides similar `@MockkBean` and `@SpykBean` annotations.
149149

150150

151151

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/native-image/testing-native-applications.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ For example, you might choose to run native tests once a day.
5858
Spring Framework includes ahead-of-time support for running tests.
5959
All the usual Spring testing features work with native image tests.
6060
For example, you can continue to use the `@SpringBootTest` annotation.
61-
You can also use Spring Boot xref:features/testing.adoc#features.testing.spring-boot-applications.autoconfigured-tests[test slices] to test only specific parts of your application.
61+
You can also use Spring Boot xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[test slices] to test only specific parts of your application.
6262

6363
Spring Framework's native testing support works in the following way:
6464

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[[testing]]
2+
= Testing
3+
4+
Spring Boot provides a number of utilities and annotations to help when testing your application.
5+
Test support is provided by two modules: `spring-boot-test` contains core items, and `spring-boot-test-autoconfigure` supports auto-configuration for tests.
6+
7+
Most developers use the `spring-boot-starter-test` "`Starter`", which imports both Spring Boot test modules as well as JUnit Jupiter, AssertJ, Hamcrest, and a number of other useful libraries.
8+
9+
[TIP]
10+
====
11+
If you have tests that use JUnit 4, JUnit 5's vintage engine can be used to run them.
12+
To use the vintage engine, add a dependency on `junit-vintage-engine`, as shown in the following example:
13+
14+
[source,xml]
15+
----
16+
<dependency>
17+
<groupId>org.junit.vintage</groupId>
18+
<artifactId>junit-vintage-engine</artifactId>
19+
<scope>test</scope>
20+
<exclusions>
21+
<exclusion>
22+
<groupId>org.hamcrest</groupId>
23+
<artifactId>hamcrest-core</artifactId>
24+
</exclusion>
25+
</exclusions>
26+
</dependency>
27+
----
28+
====
29+
30+
`hamcrest-core` is excluded in favor of `org.hamcrest:hamcrest` that is part of `spring-boot-starter-test`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[testing.spring-applications]]
2+
= Testing Spring Applications
3+
4+
One of the major advantages of dependency injection is that it should make your code easier to unit test.
5+
You can instantiate objects by using the `new` operator without even involving Spring.
6+
You can also use _mock objects_ instead of real dependencies.
7+
8+
Often, you need to move beyond unit testing and start integration testing (with a Spring `ApplicationContext`).
9+
It is useful to be able to perform integration testing without requiring deployment of your application or needing to connect to other infrastructure.
10+
11+
The Spring Framework includes a dedicated test module for such integration testing.
12+
You can declare a dependency directly to `org.springframework:spring-test` or use the `spring-boot-starter-test` "`Starter`" to pull it in transitively.
13+
14+
If you have not used the `spring-test` module before, you should start by reading the {url-spring-framework-docs}/testing.html[relevant section] of the Spring Framework reference documentation.

0 commit comments

Comments
 (0)