/springmockedtests

Demo app that shows a concise way to do integration tests mixed with mocks in Spring Framework with JUnit and Mockito

Primary LanguageJavaMIT LicenseMIT

Spring Integration Tests With Mocks

Reducing a bit of boilerplate in integration tests that contain mocks in Spring Framework using JUnit and Mockito

This is a demo/sample app to show an idea how to write concise integration tests in Spring Framework that include a mix of Spring managed beans and beans mocked with Mockito. Created for demo purposes for this article.

The most interesting stuff happens in UserServiceImplIntegrationTest. The classes used for simplified mocking are MockedBeans and MockImportRegistrar.

Aside from that, it shows how to create standalone console application with:

  • Spring Framework
  • JPA / Hibernate
  • Spring Data
  • Tested with JUnit and Mockito

I hope you find it useful! If you like this concept of mocking in integration tests, check out this repo that takes it a bit further and adds support for spies and other extras: https://github.com/hobo05/mockitobeans .

-- Kresimir