Home »
MCQs
JUnit Multiple-Choice Questions (MCQs)
JUnit is a unit testing framework for the Java programming language.
JUnit MCQs: This section contains multiple-choice questions and answers on the various topics of JUnit. Practice these MCQs to test and enhance your skills on JUnit.
List of JUnit MCQs
1. The JUnit testing framework is an ____-source tool for Java developers.
- Open
- Closed
- Both a and b
- None of the above
Answer: A) Open
Explanation:
The JUnit testing framework is an open-source tool for Java developers.
Discuss this Question
2. Code for unit tests ensures that the ____ of a program works as it should.
- Logic
- Data
- Set
- Array
Answer: A) Logic
Explanation:
Code for unit tests ensures that the logic of a program works as it should.
Discuss this Question
3. ____, After, and others are some of the classes and interfaces contained in the org.junit package for junit testing.
- Assert
- Test
- Before
- All of the above
Answer: D) All of the above
Explanation:
Assert, Test, Before, After, and others are some of the classes and interfaces contained in the org.junit package for junit testing.
Discuss this Question
4. How many types of unit testing are there?
- 2
- 3
- 4
- 5
Answer: A) 2
Explanation:
There are 2 types of unit testing.
Discuss this Question
5. Which of the following is/are the type(s) of unit testing?
- Manual
- Automated
- Both A and B
- None of the above
Answer: C) Both A and B
Explanation:
The following are the types of unit testing -
- Manual
- Automated
Discuss this Question
6. ____ testing refers to the process of executing test cases manually without any support from tools.
- Manual
- Automated
- Both a and b
- None of the above
Answer: A) Manual
Explanation:
Manual testing refers to the process of executing test cases manually without any support from tools.
Discuss this Question
7. There is a ____ with manual testing.
- Time Commitment
- Lack of reliability
- Both A and B
- None of the above
Answer: C) Both A and B
Explanation:
There is a time commitment and a lack of reliability with manual testing.
Discuss this Question
8. ____ testing is when test cases are executed with the help of a tool.
- Manual
- Automated
- Both A and B
- None of the above
Answer: B) Automated
Explanation:
Automated testing is when test cases are executed with the help of a tool.
Discuss this Question
9. The ____ of automated testing are greater.
- Speed
- Reliability
- Both A and B
- None of the above
Answer: C) Both A and B
Explanation:
The speed and reliability of automated testing are greater.
Discuss this Question
10. In the ____ annotation, the method is specified as a test method.
- @Test
- @Before
- @Test(timeout=1000)
- @After
Answer: A) @Test
Explanation:
In the @Test annotation, the method is specified as a test method.
Discuss this Question
11. When the time out exceeds 1000 milliseconds (1 second), the ____ annotation is used to indicate that the method will fail.
- @AfterClass
- @Before
- @Test(timeout=1000)
- @After
Answer: C) @Test(timeout=1000)
Explanation:
When the time-out exceeds 1000 milliseconds (1 second), the @Test(timeout=1000) annotation is used to indicate that the method will fail.
Discuss this Question
12. Invocation of the method ____ will only happen once before all tests are run.
- @AfterClass
- @Before
- @BeforeClass
- @After
Answer: C) @BeforeClass
Explanation:
Invocation of the method @BeforeClass will only happen once, before all tests are run.
Discuss this Question
13. ____ annotation indicates that the method must be called before every test.
- @AfterClass
- @Before
- @BeforeClass
- @Test(timeout=1000)
Answer: B) @Before
Explanation:
@Before annotation indicates that the method must be called before every test.
Discuss this Question
14. Program logic can be asserted using the ____ class.
- Org
- Org.junit
- org.junit.Assert
- None
Answer: C) org.junit.Assert
Explanation:
Program logic can be asserted using the org.junit.Assert class.
Discuss this Question
15. A primitive or object can be checked to be equal by calling ____.
- void assertEquals(boolean expected,boolean actual)
- void assertTrue(boolean condition)
- void assertFalse(boolean condition)
- void assertNull(Object obj)
Answer: A) void assertEquals(boolean expected,boolean actual)
Explanation:
A primitive object can be checked to be equal by calling void assertEquals(boolean expected, boolean actual).
Discuss this Question
16. Invocation of a method after all tests have been completed is specified by the ____ annotation.
- @AfterClass
- @After
- @BeforeClass
- @Test(timeout=1000)
Answer: A) @AfterClass
Explanation:
Invocation of a method after all tests have been completed is specified by the @AfterClass annotation
Discuss this Question
17. Which of the following checks if the condition is TRUE?
- void assertEquals(boolean expected,boolean actual)
- void assertTrue(boolean condition)
- void assertFalse(boolean condition)
- void assertNull(Object obj)
Answer: B) void assertTrue(boolean condition)
Explanation:
void assertTrue(boolean condition) checks if the condition is TRUE.
Discuss this Question
18. Which of the following checks if the condition is FALSE?
- void assertNotNull(Object obj)
- void assertTrue(boolean condition)
- void assertFalse(boolean condition)
- void assertNull(Object obj)
Answer: C) void assertFalse(boolean condition)
Explanation:
void assertFalse(boolean condition) checks if the condition is FALSE.
Discuss this Question
19. Which of the following checks if the object is NULL?
- void assertNotNull(Object obj)
- void assertNull(Object obj)
- void assertNullNot(Object obj)
- void assertNullValue(Object obj)
Answer: B) void assertNull(Object obj)
Explanation:
void assertNull(Object obj) checks if the object is NULL.
Discuss this Question
20. Which of the following checks if the object is NOT NULL?
- void assertNotNull(Object obj)
- void assertNull(Object obj)
- void assertNullNot(Object obj)
- void assertNullValue(Object obj)
Answer: A) void assertNotNull(Object obj)
Explanation:
void assertNotNull(Object obj) checks if the object is NOT NULL.
Discuss this Question