All questions
Showing of 51What is JUnit 5 and how does it differ from JUnit 4?
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:
Last attempt -
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
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 ↓
What are the minimum requirements to run JUnit 5?
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:
Last attempt -
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>
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 ↓
What are the main annotations in JUnit 5?
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:
Last attempt -
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
}
}
}
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 ↓
How do @BeforeAll and @AfterAll differ from @BeforeEach and @AfterEach?
What is @DisplayName and how does it improve test readability?
What are the main assertion methods in JUnit 5?
How do you test exceptions in JUnit 5?
What is Mockito and why is it used in unit testing?
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:
Last attempt -
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.
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 ↓
How do you add Mockito to a Java project?
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:
Last attempt -
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>
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 ↓
What are the different ways to create a mock in Mockito?
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:
Last attempt -
There are several ways to create mocks in Mockito:
- Using mock() method:
List<String> mockList = mock(List.class);
- Using @Mock annotation:
@Mock
private List<String> mockList;
- Using @MockBean (Spring Boot):
@MockBean
private UserService userService;
- Using MockitoAnnotations.openMocks():
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}
The annotation approach is preferred as it makes tests cleaner and more readable.
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 ↓
How do you verify that a method was called in Mockito?
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:
Last attempt -
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.
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 ↓
What are argument matchers and when should you use them?
How do you mock methods to throw exceptions?
How do you mock void methods?
Explain the architecture of JUnit 5
How does @Nested annotation work and what are its benefits?
What is assertAll() and when should you use it?
What is @TestInstance and how does it affect test lifecycle?
How do you control test execution order in JUnit 5?
How do you create parameterized tests in JUnit 5?
How do you customize display names for parameterized tests?
What are dynamic tests and when would you use them?
What's the difference between parameterized tests and dynamic tests?
How do you implement conditional test execution in JUnit 5?
How do you migrate from JUnit 4 to JUnit 5?
What is the difference between a mock, stub, and spy?
Explain the difference between when().thenReturn() and doReturn().when()
How do you stub consecutive calls to return different values?
What is the difference between verify() and verifyNoInteractions()?
How do you verify the order of method calls?
What is the @Captor annotation and how is it used?
When should you use @Spy instead of @Mock?
Explain the difference between @Mock, @MockBean, and @InjectMocks
How do you test that your code properly handles exceptions?
What are some Mockito best practices and common pitfalls?
What is the JUnit 5 extension model?
How do you create a custom extension in JUnit 5?
How do you configure parallel test execution in JUnit 5?
What are the best practices for writing effective JUnit 5 tests?
How do you create custom argument matchers?
What are the limitations of spying on objects?
How does @InjectMocks work and what are its limitations?
How do you mock static methods in Mockito?
How do you mock final classes and methods?
What is MockedConstruction and when would you use it?
What is the Answer interface and how is it used?
How do you handle flaky tests caused by Mockito?
What are the performance implications of using Mockito?
How do you test interaction between multiple mocked objects?
What are MockMaker and Mockito extensions?
How do you handle Mockito with modern Java features?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
JUnit 5 & Mockito cheatsheet
- JUnit Basics01
- Essential Annotations02
- Basic Test Structure03
- Assertions04
- Parameterized Tests05
- Test Lifecycle & Instance06
- Nested Tests07
- Conditional Tests08
- Assumptions09
- Test Doubles (Mocking)10
- Test Fixtures & Resources11
- Best Practices12
- + 7 more inside
- + 13 more inside
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.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.