Explore topic-wise MCQs in Java.

This section includes 9 Mcqs, each offering curated multiple-choice questions to sharpen your Java knowledge and support exam preparation. Choose a topic below to get started.

1.

What is used to inject mock fields into the tested object automatically?

A. @InjectMocks
B. @Inject
C. @InjectMockObject
D. @Mock
Answer» B. @Inject
2.

How can we simulate if then behavior in Junits?

A. if{..} else{..}
B. if(..){..} else{..}
C. Mockito.when(…).thenReturn(…);
D. Mockito.if(..).then(..);
Answer» D. Mockito.if(..).then(..);
3.

How to let junits know that they need to be run using PowerMock?

A. @PowerMock
B. @RunWith(PowerMock)
C. @RunWith(Junits)
D. @RunWith(PowerMockRunner.class)
Answer» E.
4.

What does assertSame() method use for assertion?

A. equals() method
B. isEqual() method
C. ==
D. compare() method
Answer» D. compare() method
5.

Which method is used to verify the actual and expected results in Junits?

A. assert()
B. equals()
C. ==
D. isEqual()
Answer» B. equals()
6.

Which of these is not a mocking framework?

A. EasyMock
B. Mockito
C. PowerMock
D. MockJava
Answer» E.
7.

Which of the below is an incorrect annotation with respect to JUnits?

A. @Test
B. @BeforeClass
C. @Junit
D. @AfterEach
Answer» D. @AfterEach
8.

Which of the below statement about JUnit is false?

A. It is an open source framework
B. It provides an annotation to identify test methods
C. It provides test runners for running test
D. They cannot be run automatically
Answer» E.
9.

JUnits are used for which type of testing?

A. Unit Testing
B. Integration Testing
C. System Testing
D. Blackbox Testing
Answer» B. Integration Testing