SoftwareTestPilot
26 JUnit 5 Q&A

JUnit Interview Questions for Automation Testing (1970)

26 real JUnit 5 interview questions with senior-SDET answers and Java code — Jupiter architecture, lifecycle annotations, assertions & assumptions, parameterized & dynamic tests, extensions, parallel execution, and Selenium / REST Assured integration.

  • 3 min read
  • Difficulty: Mixed (Easy → Medium)
  • Freshers → 5+ yrs
  • Updated July 1970
  • Avinash Kamble

1. JUnit 5 Basics

Easy Very Common 1 min read

Q1.What is JUnit?

JUnit is the de-facto Java unit testing framework. JUnit 5 (aka Jupiter) is the 2026 default — modular architecture, native parameterized tests, dynamic tests, and rich extension model.

Easy Very Common 1 min read

Q2.Why use JUnit for automation testing?

Every Java-based automation stack (Selenium, REST Assured, Playwright-Java, Appium) integrates natively with a JUnit runner. JUnit provides the lifecycle, assertions, and parallel-execution plumbing so automation code stays focused on test logic.

Easy Very Common 1 min read

Q3.JUnit 5 architecture — what are the three sub-projects?

  • JUnit Platform — foundation for launching testing frameworks on the JVM
  • JUnit Jupiter — the new API for writing tests (@Test, extensions)
  • JUnit Vintage — backwards-compat runner for JUnit 3/4 tests
Medium Very Common 1 min read

Q4.How do you add JUnit 5 to Maven?

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter</artifactId>
  <version>5.10.2</version>
  <scope>test</scope>
</dependency>
Medium Very Common 1 min read

Q5.How do you run a single JUnit test?

mvn test -Dtest=LoginTest#validCredentials
# Gradle
./gradlew test --tests LoginTest.validCredentials
Confidence check

If you can confidently answer the JUnit 5 Basics questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

2. Annotations & Lifecycle

Medium Very Common 1 min read

Q6.List the main JUnit 5 lifecycle annotations.

  • @BeforeAll / @AfterAll — once per class (static by default)
  • @BeforeEach / @AfterEach — before/after every test
  • @Test, @RepeatedTest, @ParameterizedTest
  • @Disabled, @Tag, @Nested, @Timeout
Medium Very Common 1 min read

Q7.@Before vs @BeforeEach vs @BeforeAll — what changed in JUnit 5?

JUnit 4 used @Before / @BeforeClass. JUnit 5 renamed them to @BeforeEach / @BeforeAll for clarity. Same semantics: per-test vs per-class-once.

Medium Very Common 1 min read

Q8.Can @BeforeAll be non-static?

Yes — annotate the class with @TestInstance(Lifecycle.PER_CLASS). Otherwise it must be static.

Medium Very Common 1 min read

Q9.How do you group tests?

@Test @Tag("smoke") @Tag("regression")
void loginTest() {}
mvn test -Dgroups=smoke
Medium Very Common 1 min read

Q10.How do you use @Nested?

class OrderTest {
  @Nested class WhenLoggedIn {
    @Test void canCheckout() {}
  }
}

Great for BDD-style grouping.

Medium Common 1 min read

Q11.How do you set a timeout?

@Test @Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
void mustBeFast() {}
Confidence check

If you can confidently answer the Annotations & Lifecycle questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

3. Assertions & Assumptions

Medium Common 1 min read

Q12.What assertion library does JUnit 5 provide?

import static org.junit.jupiter.api.Assertions.*;
assertEquals(expected, actual);
assertTrue(list.contains("qa"));
assertThrows(IllegalArgumentException.class, () -> svc.create(null));
assertAll("user",
  () -> assertEquals("Ada", user.name()),
  () -> assertTrue(user.active())
);
Easy Common 1 min read

Q13.assertAll vs assertEquals — when do you use assertAll?

When you want to check multiple properties and see all failures at once instead of stopping at the first one. Similar to TestNG's soft assertions.

Medium Common 1 min read

Q14.What are Assumptions?

assumeTrue(System.getenv("CI") != null);
// Test is aborted (not failed) if the assumption is false
Medium Common 1 min read

Q15.Difference between assertThrows and assertDoesNotThrow?

assertThrows passes only if the expected exception is thrown. assertDoesNotThrow passes only if no exception is thrown — used for happy-path safety nets.

Confidence check

If you can confidently answer the Assertions & Assumptions questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

4. Parameterized & Dynamic Tests

Medium Common 1 min read

Q16.What is @ParameterizedTest?

@ParameterizedTest
@ValueSource(strings = {"admin@x.com", "qa@x.com"})
void isEmail(String s) { assertTrue(s.contains("@")); }
Medium Common 1 min read

Q17.How do you supply CSV data?

@ParameterizedTest
@CsvSource({ "1,2,3", "5,7,12" })
void add(int a, int b, int expected) {
  assertEquals(expected, a + b);
}
Medium Common 1 min read

Q18.How do you use @MethodSource?

static Stream<Arguments> logins() {
  return Stream.of(arguments("a@x.com","p"), arguments("b@x.com","q"));
}
@ParameterizedTest @MethodSource("logins")
void login(String email, String pwd) {}
Medium Common 1 min read

Q19.What is a Dynamic Test?

@TestFactory
Collection<DynamicTest> dyn() {
  return List.of(
    dynamicTest("sums to 3", () -> assertEquals(3, 1 + 2))
  );
}

Generate tests at runtime from data.

Medium Occasional 1 min read

Q20.@RepeatedTest — when to use it?

@RepeatedTest(10) void flakyGuard() {}

Great for catching intermittent race conditions in automation.

Confidence check

If you can confidently answer the Parameterized & Dynamic Tests questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

5. Selenium/REST Assured Integration

Medium Occasional 1 min read

Q21.How do you integrate JUnit 5 with Selenium?

class LoginTest {
  WebDriver driver;
  @BeforeEach void up() { driver = new ChromeDriver(); }
  @AfterEach void down() { driver.quit(); }
  @Test void loginSucceeds() { /* ... */ }
}

See our Selenium Q&A bank.

Medium Occasional 1 min read

Q22.How do you integrate JUnit 5 with REST Assured?

@Test
void getUser() {
  given().baseUri("https://api.x.com")
    .when().get("/users/1")
    .then().statusCode(200)
    .body("email", containsString("@"));
}

Deep dives in our API Testing Q&A.

Medium Occasional 1 min read

Q23.How do you run JUnit 5 tests in parallel?

# src/test/resources/junit-platform.properties
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4
Medium Occasional 1 min read

Q24.What is a JUnit 5 Extension?

The replacement for JUnit 4's Runners and Rules. Implement callbacks like BeforeEachCallback, TestExecutionExceptionHandler. Common uses: screenshot-on-failure, Testcontainers, Spring integration.

Medium Occasional 1 min read

Q25.How do you fail a test on the first exception in a suite?

junit.jupiter.execution.parallel.enabled=false

Then use Surefire's -Dsurefire.skipAfterFailureCount=1 to bail early — useful in smoke pipelines.

Medium Occasional 1 min read

Q26.How do you integrate JUnit with GitHub Actions?

- run: mvn -B test
- uses: actions/upload-artifact@v4
  if: always()
  with: { name: surefire, path: target/surefire-reports/ }
- uses: mikepenz/action-junit-report@v4
  if: always()
  with: { report_paths: 'target/surefire-reports/*.xml' }
Confidence check

If you can confidently answer the Selenium/REST Assured Integration questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

Quick revision

  1. Q1: What is JUnit — JUnit is the de-facto Java unit testing framework.
  2. Q2: Why use JUnit for automation testing — Every Java-based automation stack (Selenium, REST Assured, Playwright-Java, Appium) integrates natively with a JUnit runner.
  3. Q3: JUnit 5 architecture — what are the three sub-projects — JUnit Platform — foundation for launching testing frameworks on the JVM JUnit Jupiter — the new API for writing tests (@Test, extensions) JUnit Vintage — backwards-compat runner fo
  4. Q4: How do you add JUnit 5 to Maven — &lt;dependency&gt; &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt; &lt;artifactId&gt;junit-jupiter&lt;/artifactId&gt; &lt;version&gt;5.10.2&lt;/version&gt; &lt;scope&gt;test&lt;/s
  5. Q5: How do you run a single JUnit test — mvn test -Dtest=LoginTest#validCredentials # Gradle ./gradlew test --tests LoginTest.validCredentials

Frequently asked questions

Yes — JUnit 5 is the standard for Java unit and integration tests, and every Selenium/REST Assured/Playwright-Java stack plugs into a JUnit runner.

Modern teams pick JUnit 5 for greenfield projects (better extension model, native parallel, Spring/Testcontainers integration). Legacy Selenium suites still ship on TestNG.

Java 8 works, but the ecosystem has moved to Java 17 LTS. Testcontainers 2.x and Spring Boot 3.x require it, so pair JUnit 5 with Java 17+ in 2026.

Clone an OSS Spring Boot sample, delete a test class, and rewrite it. Then run our AI Mock Interview on this exact topic.

Was this article helpful?

Cluster · QA Career

More from QA Interview Questions

Behavioral, framework, coding — full interview prep.

Pillar guide · 10 articles
More in this cluster
From the QA Career pillar

Key takeaways

  • Master the fundamentals before tackling advanced JUnit scenarios.
  • Always explain trade-offs — interviewers reward judgement, not memorisation.
  • Use real project examples; generic answers blend in.
  • Practice answers out loud — written prep doesn't transfer to live rounds.
  • Revise the 30-second cheat sheet the night before your interview.
  • Keep one strong scenario story ready for every section above.

These Questions Are Just the Start

Get 1000+ more with detailed model answers in our QA Interview Preparation Kit. Covers manual testing, automation, API, SQL, Selenium, Playwright, and framework concepts — everything asked in real QA interviews.

Get Interview Kit — ₹1,045

JUnit jobs hiring now

Live, indexable JUnit openings — updated daily in Jobs Radar.

Browse all QA jobs on Jobs Radar

Loading current openings…

Home