Skip to content

Commit

Permalink
Link to @⁠MockitoBean, @⁠MockitoSpyBean, & @⁠TestBean Javadoc from re…
Browse files Browse the repository at this point in the history
…f docs
  • Loading branch information
sbrannen committed Feb 12, 2025
1 parent e31ce35 commit 6174055
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[[spring-testing-annotation-beanoverriding-mockitobean]]
= `@MockitoBean` and `@MockitoSpyBean`

`@MockitoBean` and `@MockitoSpyBean` can be used in test classes to override a bean in
the test's `ApplicationContext` with a Mockito _mock_ or _spy_, respectively. In the
latter case, an early instance of the original bean is captured and wrapped by the spy.
{spring-framework-api}/test/context/bean/override/mockito/MockitoBean.html[`@MockitoBean`] and
{spring-framework-api}/test/context/bean/override/mockito/MockitoSpyBean.html[`@MockitoSpyBean`]
can be used in test classes to override a bean in the test's `ApplicationContext` with a
Mockito _mock_ or _spy_, respectively. In the latter case, an early instance of the
original bean is captured and wrapped by the spy.

The annotations can be applied in the following ways.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[[spring-testing-annotation-beanoverriding-testbean]]
= `@TestBean`

`@TestBean` is used on a non-static field in a test class to override a specific bean in
the test's `ApplicationContext` with an instance provided by a factory method.
{spring-framework-api}/test/context/bean/override/convention/TestBean.html[`@TestBean`]
is used on a non-static field in a test class to override a specific bean in the test's
`ApplicationContext` with an instance provided by a factory method.

The associated factory method name is derived from the annotated field's name, or the
bean name if specified. The factory method must be `static`, accept no arguments, and
Expand Down

0 comments on commit 6174055

Please sign in to comment.