Skip to content
Discussion options

You must be logged in to vote

Hi @NicoPolazzi, in my experience, pure JUnit tests are usually enough for unit tests without needing any test utility from the Spring projects. See also this Spring Boot blog post, which mentions:

The easiest way to unit test any Spring @Component is to not involve Spring at all! It’s always best to try and structure your code so that classes can be instantiated and tested directly. Usually that boils down to a few things:

  • Structure your code with clean separation of concerns so that individual parts can be unit tested. TDD is a good way to achieve this.
  • Use constructor injection to ensure that objects can be instantiated directly. Don’t use field injection as it just makes your tests …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NicoPolazzi
Comment options

Answer selected by NicoPolazzi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants