You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/dev-services.adoc
+4-4
Original file line number
Diff line number
Diff line change
@@ -286,7 +286,7 @@ spring:
286
286
[[features.dev-services.testcontainers]]
287
287
== Testcontainers Support
288
288
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.
290
290
The next sections will provide more details about that.
291
291
292
292
@@ -312,7 +312,7 @@ To do this, you need to make sure that the `spring-boot-testcontainers` module h
312
312
Once that has been done, you can create a `@TestConfiguration` class that declares `@Bean` methods for the containers you want to start.
313
313
314
314
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.
316
316
317
317
A typical Testcontainers configuration would look like this:
318
318
@@ -338,7 +338,7 @@ TIP: You can use the Maven goal `spring-boot:test-run` or the Gradle task `bootT
338
338
==== Contributing Dynamic Properties at Development Time
339
339
340
340
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.
342
342
It allows you to add properties that will become available once your container has started.
343
343
344
344
A typical configuration would look like this:
@@ -365,7 +365,7 @@ To do so, add the `@ImportTestcontainers` annotation to your test configuration
365
365
366
366
include-code::MyContainersConfiguration[]
367
367
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.
369
369
You can also add `@DynamicPropertySource` annotated methods to your declaration class.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc
+1-1
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Sources are considered in the following order:
24
24
. Properties from `SPRING_APPLICATION_JSON` (inline JSON embedded in an environment variable or system property).
25
25
. Command line arguments.
26
26
. `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].
28
28
. {url-spring-framework-javadoc}/org/springframework/test/context/DynamicPropertySource.html[`@DynamicPropertySource`] annotations in your tests.
29
29
. {url-spring-framework-javadoc}/org/springframework/test/context/TestPropertySource.html[`@TestPropertySource`] annotations on your tests.
30
30
. xref:using/devtools.adoc#using.devtools.globalsettings[Devtools global settings properties] in the `$HOME/.config/spring-boot` directory when devtools is active.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc
+1-1
Original file line number
Diff line number
Diff line change
@@ -145,7 +145,7 @@ JUnit 5 enables a test class to be instantiated once and reused for all of the c
145
145
This makes it possible to use `@BeforeAll` and `@AfterAll` annotations on non-static methods, which is a good fit for Kotlin.
146
146
147
147
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.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/native-image/testing-native-applications.adoc
+1-1
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ For example, you might choose to run native tests once a day.
58
58
Spring Framework includes ahead-of-time support for running tests.
59
59
All the usual Spring testing features work with native image tests.
60
60
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.
62
62
63
63
Spring Framework's native testing support works in the following way:
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`.
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