SDET: JUnit interview questions for automation engineer

Carvia Tech | October 26, 2019 | 2 min read | 818 views

In this article we will cover important interview questions around Junit 4 and Junit 5 for every automation SDET engineer.

  1. How will you write a basic test case using JUnit

  2. Why do you write Unit tests in isolation?

  3. Can we only write unit tests using JUnit and not the integration tests?

  4. How does Junit compares with TestNG and other frameworks like BDD/Cucumber/etc?

  5. How will you group Junit 5 testcases based on functionality or other parameters?

  6. How to create custom Junit 5 meta annotation for a Tag

  7. How to programmatically run Junit 5 testcases for a specific Tag/Class/Package using Java/Kotlin code?

  8. How to make certain testcase run on a specific environment/machine/os only, skip otherwise?

  9. How to write integration testcase using Junit 5?

  10. How to write API testcases using Junit 5?

  11. How to specify order of execution for testcases? Should’d testcase be written in such a way that they can be run independent of execution order?

  12. How to write dynamic testcase in Junit 5? Write dynamic testcases for asserting recently developed palindrome function.

  13. What are parameterized tests in Junit 5? How to write a simple Parameterized test? When to use parameterized tests?

  14. How will you compare parameterized tests with dynamic tests?

  15. Write a simple Junit 5 testcase that checks a REST API for unauthorized access?

  16. What are advantages of using JUnit 5 over JUnit 4

  17. Explain Mike Cohn’s test pyramid

  18. Hemcrest matchers introduction

  19. AssertJ introduction

  20. How will you write a junit testcase that checks if the given exception was thrown with provided message

  21. What is difference between Assertions and Assumptions in Junit?

  22. How will you enable certain Junit 5 testcase only on certain Operating System?

  23. How to enable certain Junit Jupiter tests only on System Property Conditions

  24. How to enable certain Junit Jupiter tests based on environment variable condition?

Advanced Junit Concepts

  1. How to write a custom test execution listener that sends email for failures

  2. Parameterized testcase that reads test cases from CSV file

  3. What are data driven testcase, how to write them using JUnit 5

  4. Write a test case that loads data from CSV input

REST API Testing

  1. How to handle OAuth2 login using JUnit based tests

  2. What are different libraries for API testing? HttpClient, RestTemplate, WebClient, WebTestClient, RestAssured, how do you compare them?

  3. What is difference between RestAssured and Spring RestTemplate from testing perspective?

  4. How will you assert the value of a specific node in JSON returned by an API

  5. What are Contract Driven Tests? When will you use them?

  6. How will you write a testcase to assert that unauthorized user is not allowed to access a specific API

Top articles in this category:
  1. 50 SDET Java Interview Questions & Answers
  2. Rest Assured API Testing Interview Questions
  3. SDET Java Coding Challenges
  4. Migrating Spring Boot tests from Junit 4 to Junit 5
  5. How to reverse a number in Java
  6. SDET Java Role - Essential Skills
  7. JUnit 5 Parameterized Tests

Find more on this topic:

Recommended books for interview preparation: