Software Alternatives & Reviews

Mockito VS JUnit

Compare Mockito VS JUnit and see what are their differences

Mockito logo Mockito

Mocking framework for unit tests in Java.

JUnit logo JUnit

JUnit is a simple framework to write repeatable tests.
  • Mockito Landing page
    Landing page //
    2021-10-17
  • JUnit Landing page
    Landing page //
    2022-12-12

Mockito videos

Mockito JUnit Example

More videos:

  • Tutorial - Mockito Tutorial - Mocking With Junit and Maven
  • Review - Mockito Annotations - @Mock, @Runwith, @InjectMocks and @Captor

JUnit videos

Code Review of example Project for JUnit 5 Tests

More videos:

  • Review - JUnit - Features
  • Review - JUnit test case example in Java – CM004

Category Popularity

0-100% (relative to Mockito and JUnit)
Automated Testing
31 31%
69% 69
Testing
34 34%
66% 66
Browser Testing
100 100%
0% 0
Developer Tools
0 0%
100% 100

User comments

Share your experience with using Mockito and JUnit. For example, how are they different and which one is better?
Log in or Post with

Social recommendations and mentions

JUnit might be a bit more popular than Mockito. We know about 16 links to it since March 2021 and only 14 links to Mockito. We are tracking product recommendations and mentions on various public social media platforms and blogs. They can help you identify which product is more popular and what people think of it.

Mockito mentions (14)

  • I build CRUDS as an intern. My boss told me my tests were ok, but too slow, so he modified them to run in a specific order to reuse the app context on all tests. Is that a good practice though?
    I would say no. Mocking is generally creating a mock object. Like with Mockito. https://site.mockito.org. Source: 12 months ago
  • Instancio 2.2.0 released
    Could you explain how this relates to Mockito? Could it be used together perhaps for more advanced mocking? Source: over 1 year ago
  • Testing JSch SFTP Code
    You could use mocks, but you'd basically be implementing JSch. I'm not mocking a framework, and recently learned my misgivings have a name: the soviet police station anti-pattern. Source: over 1 year ago
  • Create and use a result captor in Mockito
    In Mockito it exists the possibilty to use ArgumentCaptor to allow developers to verify the arguments used during the call of mocked method, but not the result itself. Indeed, in the current release of Mockito it's not possible to capture it and my solution to do that is to build a ResultCaptor class which implements the Answer interface and generify it for more conveniance. - Source: dev.to / almost 2 years ago
  • Reverse engineering Mockito. Part 1. Single use case
    So I am building my own little project, which you can read about HERE and I have made the decision to use as few libraries as possible. Now that I am doing some testing I need some mock objects, which means I have to try to recreate Mockito. So this series will be me recreating Mockito the best I can. This post will be about creating a simple single use case implementation that gets our annotation working. It... - Source: dev.to / about 2 years ago
View more

JUnit mentions (16)

  • Setting up Continuous Integration
    Unlike I expected, setting up the project with Junit proved to be really time-consuming for me. - Source: dev.to / 5 months ago
  • Adding testing for my java project
    First, I chose a testing framework for my java project. JUnit is the most pupular testing framework for java. - Source: dev.to / 6 months ago
  • How to prevent NullPointerExceptions in Java
    This code defines a JUnit test case for the getStrings() method of the MyClass class. Then it creates an instance of MyClass, calls the getStrings() method, and asserts that the result is not null using the assertNotNull() method. - Source: dev.to / 7 months ago
  • JUnit 5: link tests with task tracker issues
    How you can link JUnit 5 tests with issues in your task tracker systems? - Source: dev.to / about 1 year ago
  • DevOps Tooling Landscape
    JUnit is a popular Java testing framework used for unit testing. It's an open-source tool that's designed to make it easy for developers to write and run automated tests. JUnit provides a set of annotations and assertions that can be used to define test cases and expected outcomes, and it can be easily integrated with other DevOps tools like Jenkins and Maven. - Source: dev.to / about 1 year ago
View more

What are some alternatives?

When comparing Mockito and JUnit, you can also consider the following products

Cucumber - Cucumber is a BDD tool for specification of application features and user scenarios in plain text.

Robot framework - Robot Framework is a generic test automation framework for acceptance testing and acceptance...

RSpec - RSpec is a testing tool for the Ruby programming language born under the banner of Behavior-Driven Development featuring a rich command line program, textual descriptions of examples, and more.

Spring Framework - The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform.

PHPUnit - Application and Data, Build, Test, Deploy, and Testing Frameworks

Mob4Hire - Mob4Hire provides the mobile marketplace mobile testing services.