JUnit Multiple-Choice Questions (MCQs)
Q. What is JUnit?
A Java-based web frameworkA unit testing framework for Java
A Java code compiler
A database management system for Java
Q. Which annotation is used to mark a method as a test in JUnit 5?
@TestMethod@TestCase
@Test
@UnitTest
Q. Which of the following is not an assertion method in JUnit?
assertEquals()assertTrue()
assertNull()
assertExecute()
Q. What is the purpose of the @BeforeEach annotation in JUnit 5?
To run a method before all tests in the classTo run a method before each test method
To run a method after each test method
To run a method after all tests in the class
Q. Which JUnit 5 annotation is used to disable a test?
@Ignore@Disabled
@Skip
@Inactive
Q. What is the purpose of the assertThrows() method in JUnit?
To verify that a method throws an expected exceptionTo force a method to throw an exception
To catch and ignore exceptions in a test
To assert that a method does not throw any exceptions
Q. Which of the following is true about JUnit test methods?
They must be privateThey must return a value
They must have parameters
They can be public void methods
Q. What is the purpose of the @ParameterizedTest annotation in JUnit 5?
To create tests with random parametersTo run a test multiple times with different parameters
To test methods with optional parameters
To ignore parameters in test methods
Q. Which JUnit 5 annotation is used to specify a custom display name for a test?
@TestName@DisplayName
@CustomName
@Name
Q. What is the purpose of the @TempDir annotation in JUnit 5?
To create a temporary directory for file operations during testsTo specify a directory for storing test results
To mark a directory for deletion after tests
To indicate a directory containing test resources
Q. Which of the following is NOT a lifecycle method annotation in JUnit 5?
@BeforeAll@AfterEach
@BeforeTest
@AfterAll