LearnThatStack Ace your next interview
Part of Testing

JUnit 5 & Mockito.

Start free Change topic Change
Practice · Questions

All questions

Showing of 51
Beginner 14
01

What is JUnit 5 and how does it differ from JUnit 4?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

JUnit 5 is the next generation of the JUnit testing framework for Java applications. Unlike JUnit 4's monolithic design, JUnit 5 consists of three modular subprojects:

Architecture:

  • JUnit Platform: Foundation for launching testing frameworks on the JVM
  • JUnit Jupiter: Programming and extension model for writing tests and extensions
  • JUnit Vintage: Provides backward compatibility for JUnit 3 and 4 tests

Key Improvements from JUnit 4:

  • Java 8+ Requirement: Leverages lambda expressions and functional interfaces
  • Enhanced Annotations: More descriptive and flexible annotations
  • Dynamic Tests: Runtime test generation capabilities
  • Powerful Extension Model: Replaces runners with more flexible extensions
  • Better Assertions: Improved assertion methods with lambda support
  • Nested Test Organization: Better test structure with @Nested
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What are the minimum requirements to run JUnit 5?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

System Requirements:

  • Java 8 or higher: JUnit 5 requires minimum Java 8
  • Build Tool Support: Maven 3.3+ or Gradle 4.6+
  • IDE Support: Most modern IDEs support JUnit 5

Maven Dependency:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.9.2</version>
    <scope>test</scope>
</dependency>

Gradle Dependency:

testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'

Surefire Plugin Configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M8</version>
</plugin>
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What are the main annotations in JUnit 5?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Core Test Annotations:

  • @Test: Marks a method as a test method
  • @ParameterizedTest: Indicates a parameterized test
  • @RepeatedTest: Repeats test execution multiple times
  • @TestFactory: Defines a method for dynamic test generation

Lifecycle Annotations:

  • @BeforeEach: Executed before each test method
  • @AfterEach: Executed after each test method
  • @BeforeAll: Executed once before all test methods (static)
  • @AfterAll: Executed once after all test methods (static)

Organization Annotations:

  • @DisplayName: Provides custom display name for tests
  • @Nested: Creates nested test classes for better organization
  • @Tag: Tags tests for filtering and grouping
  • @Disabled: Disables a test method or class

Example Usage:

@DisplayName("Calculator Tests")
class CalculatorTest {
    
    @BeforeEach
    void setUp() {
        calculator = new Calculator();
    }
    
    @Test
    @DisplayName("Should add two positive numbers correctly")
    void testAddition() {
        assertEquals(5, calculator.add(2, 3));
    }
    
    @Nested
    @DisplayName("Division Tests")
    class DivisionTests {
        
        @Test
        void testValidDivision() {
            assertEquals(2, calculator.divide(10, 5));
        }
        
        @Test
        @Disabled("Division by zero behavior under review")
        void testDivisionByZero() {
            // Test implementation
        }
    }
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

How do @BeforeAll and @AfterAll differ from @BeforeEach and @AfterEach?

Part of Pro
05

What is @DisplayName and how does it improve test readability?

Part of Pro
06

What are the main assertion methods in JUnit 5?

Part of Pro
07

How do you test exceptions in JUnit 5?

Part of Pro
08

What is Mockito and why is it used in unit testing?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Mockito is a popular Java mocking framework used for unit testing. It allows developers to create mock objects that simulate the behavior of real objects in a controlled way. The main purposes of Mockito are:

  • Isolation: Test classes in isolation by mocking their dependencies
  • Control: Define specific behaviors for method calls during testing
  • Verification: Verify that certain methods were called with expected parameters
  • Speed: Avoid expensive operations like database calls or network requests

Mockito helps create fast, reliable, and focused unit tests by eliminating external dependencies.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

09

How do you add Mockito to a Java project?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Maven:

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>5.7.0</version>
    <scope>test</scope>
</dependency>

Gradle:

testImplementation 'org.mockito:mockito-core:5.7.0'

JUnit 5 integration:

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-junit-jupiter</artifactId>
    <version>5.7.0</version>
    <scope>test</scope>
</dependency>
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

10

What are the different ways to create a mock in Mockito?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

There are several ways to create mocks in Mockito:

  1. Using mock() method:
List<String> mockList = mock(List.class);
  1. Using @Mock annotation:
@Mock
private List<String> mockList;
  1. Using @MockBean (Spring Boot):
@MockBean
private UserService userService;
  1. Using MockitoAnnotations.openMocks():
@BeforeEach
void setUp() {
    MockitoAnnotations.openMocks(this);
}

The annotation approach is preferred as it makes tests cleaner and more readable.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

11

How do you verify that a method was called in Mockito?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Mockito provides the verify() method to check if methods were called:

// Verify method was called once
verify(mockList).add("item");

// Verify method was called specific number of times
verify(mockList, times(2)).add(anyString());

// Verify method was never called
verify(mockList, never()).clear();

// Verify method was called at least/at most certain times
verify(mockList, atLeast(1)).size();
verify(mockList, atMost(3)).add(anyString());

Verification should be done after the method under test has been executed.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

12

What are argument matchers and when should you use them?

Part of Pro
13

How do you mock methods to throw exceptions?

Part of Pro
14

How do you mock void methods?

Part of Pro
Intermediate 21
15

Explain the architecture of JUnit 5

Part of Pro
16

How does @Nested annotation work and what are its benefits?

Part of Pro
17

What is assertAll() and when should you use it?

Part of Pro
18

What is @TestInstance and how does it affect test lifecycle?

Part of Pro
19

How do you control test execution order in JUnit 5?

Part of Pro
20

How do you create parameterized tests in JUnit 5?

Part of Pro
21

How do you customize display names for parameterized tests?

Part of Pro
22

What are dynamic tests and when would you use them?

Part of Pro
23

What's the difference between parameterized tests and dynamic tests?

Part of Pro
24

How do you implement conditional test execution in JUnit 5?

Part of Pro
25

How do you migrate from JUnit 4 to JUnit 5?

Part of Pro
26

What is the difference between a mock, stub, and spy?

Part of Pro
27

Explain the difference between when().thenReturn() and doReturn().when()

Part of Pro
28

How do you stub consecutive calls to return different values?

Part of Pro
29

What is the difference between verify() and verifyNoInteractions()?

Part of Pro
30

How do you verify the order of method calls?

Part of Pro
31

What is the @Captor annotation and how is it used?

Part of Pro
32

When should you use @Spy instead of @Mock?

Part of Pro
33

Explain the difference between @Mock, @MockBean, and @InjectMocks

Part of Pro
34

How do you test that your code properly handles exceptions?

Part of Pro
35

What are some Mockito best practices and common pitfalls?

Part of Pro
Expert 16
36

What is the JUnit 5 extension model?

Part of Pro
37

How do you create a custom extension in JUnit 5?

Part of Pro
38

How do you configure parallel test execution in JUnit 5?

Part of Pro
39

What are the best practices for writing effective JUnit 5 tests?

Part of Pro
40

How do you create custom argument matchers?

Part of Pro
41

What are the limitations of spying on objects?

Part of Pro
42

How does @InjectMocks work and what are its limitations?

Part of Pro
43

How do you mock static methods in Mockito?

Part of Pro
44

How do you mock final classes and methods?

Part of Pro
45

What is MockedConstruction and when would you use it?

Part of Pro
46

What is the Answer interface and how is it used?

Part of Pro
47

How do you handle flaky tests caused by Mockito?

Part of Pro
48

What are the performance implications of using Mockito?

Part of Pro
49

How do you test interaction between multiple mocked objects?

Part of Pro
50

What are MockMaker and Mockito extensions?

Part of Pro
51

How do you handle Mockito with modern Java features?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for JUnit 5 & Mockito? Send them this set.
Pro · $10/mo

44 of 51 JUnit 5 & Mockito answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git