talira

Tasty mocking framework for unit tests in Java

open sourceMITfree

Mockito is a mocking framework for unit tests in Java and other JVM languages. You create mocks and spies of your classes and interfaces, stub what their methods return, and verify how they were called, with a clean, readable API and clear verification errors. It's published on Maven Central as mockito-core, with mockito-junit-jupiter for JUnit 5 integration, and released automatically by continuous delivery.

Problems it solves

  • replace a database or HTTP client with a fake in my Java unit tests
  • check that my code called a dependency with the right arguments
  • stub what a dependency returns so I can test one class in isolation
  • mock collaborators in JUnit 5 tests with annotations instead of setup code

Features

  • mocks and spies of classes and interfaces
  • stubbing return values and exceptions
  • verification of calls, arguments and call counts
  • argument matchers and captors
  • JUnit 5 integration with mockito-junit-jupiter
  • @Mock, @Spy and @InjectMocks annotations