Java Basic
- How can junits be implemented using maven?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
JUnits can be used using dependency tag in maven in pom.xml. The version as desired and available in repository can be used.
- What is used to inject mock fields into the tested object automatically?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
@InjectMocks annotation is used to inject mock fields into the tested object automatically.
- How can we simulate if then behavior in Junits?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Mockito.when(mockList.size()).thenReturn(100); assertEquals(100, mockList.size()); is the usage to implement if and then behavior.
- How to let junits know that they need to be run using PowerMock?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
@RunWith(PowerMockRunner.class) signifies to use PowerMock JUnit runner. Along with that @PrepareForTest(User.class) is used to declare the class being tested. mockStatic(Resource.class) is used to mock the static methods.
- What does assertSame() method use for assertion?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
== is used to compare the objects not the content. assertSame() method compares to check if actual and expected are the same objects. It does not compare their content.