Back to list
Mockito
FreeAPI TestingNetworkService Virtualization
About
Mockito is the leading mocking framework for Java, relied upon by more than 15,100 developers on GitHub to produce clean and maintainable unit tests with minimal boilerplate code. It offers an intuitive, fluent API that allows you to create mocks, spies, and stubs in just a few lines, leading to tests that are easy to read and clear error messages for verification. With excellent support for behavior-driven development (BDDMockito), inline mock creators, and strict stubs, it integrates seamlessly with JUnit, TestNG, Android (through DexMaker), and various other testing frameworks, ensuring extensive compatibility across projects based on the JVM.
Key Features
- Clean & Fluent API:Generate mocks using mock(), establish spies with spy(), and set behavior through when()/given() methods for simple test configurations.
- Clear Verification - Utilize verify() along with adaptable argument matchers (such as any(), eq()) or captors (@Captor) to accurately assert interactions.
- Behavior‑Driven Development (BDD) Support:Utilize a syntax reminiscent of BDD through BDDMockito.then() and given() to create test definitions that are clear and narrative in style.
- Inline Mocking & ByteBuddy Integration:Switchable mock-maker plugins enable the mocking of final classes and methods without the need for classpath manipulation, utilizing ByteBuddy as the underlying technology.
- Annotation‑Driven Injection:Automatically inject mock objects and spies into your classes with @Mock, @Spy, and @InjectMocks, simplifying the process of test setup.
- Strict Stubs & Error Reporting:Activate strict stubbing to identify unused or improperly configured stubs, minimizing false-positive test outcomes and enhancing test quality.
- Android Compatibility:Utilize Mockito in Android applications through the DexMaker framework, guaranteeing uniform functionality across both JVM and Dalvik environments.
- Comprehensive Documentation & Community:Utilize the latest Javadoc available on javadoc.io, browse the GitHub Wiki for frequently asked questions and recommended practices, or participate in the mailing list and StackOverflow tags for assistance.