r/learnjava • • Dec 24 '25

How to learn unit/integration tests?

I have paid for a course in Udemy and what it teaches is only syntax. Spending more than 10 minutes for every JUnit method.

The projects I build in spring boot are small that I think it won't be good place to learn unit testing there. Big and more complex ones would be great. Suggest me resources to learn and practice.

12 Upvotes

11 comments sorted by

View all comments

Show parent comment

2

u/TheFaustX Dec 25 '25

You test a unit of work, if the code will sort a collection of items in a certain way you don't care where the items come from. Your test will check whether the items you put in are sorted as you expect it.

  • DB Access functions using queries or aggregation should be tested by making a specific data set then call the function to fetch data as expected from the repository
  • Functions doing business logic do not need to do that if you run a layered architecture, you just test if a given output returns the expected output or calls the expected functions. This can be made easier by mocking certain things you don't care about in that specific test scenario with for example Mockito
  • Some static or utility functions like mappers don't need either of those, you can just immediately test the output and are fine