Question 1. What Are Junits ?
Junt is the unit testing framework for Java.
Question 2. Are Junits Tested Manually?
No , they are executed automatically.
Question 3. How To Test Whether The Returns Value Of The Method Is Expected ?
Question 4. Which Package Assert Belong To?
Question 5. What Happens If The Assert Doesn’t Evaluate To Be True?
Question 6. How To Create A Junit To Make Sure That The Tested Method Throws An Exception ?
Using annotation Test with the argument as expected exception.
@Test (expected = Exception.class)
Question 7. What Should I Do If I Want To Make Sure That A Particular Method Of A Class Is Getting Called ?
If its a static method of the class , we can use verify to make sure it’s getting called.
If its an instance method , We can mock the object and then use verify with the mocked object to make sure that the method is getting called.”
Question 8. Name Few Java Mocking Frameworks?
Mockito, PowerMock, EasyMock, JMock, JMockit.
Question 9. What Is The Use Of Mockito.any?
In case we need to verify that a method is being called with any argument and not a specific argument we can use Mockito.any(Class), Mockito.anyString, Mockito.anyLong etc.
Question 10. How Should We Ignore Or Avoid Executing Set Of Tests?
We can remove @Test from the respective test so as to avoid its execution. Alternatively we can put @Ignore annotation on the Junit file if we want to ignore all tests in a particular file.
Question 11. How Can We Test Methods Individually Which Are Not Visible Or Declared Private?
We can either increase their visibility and mark them with annotation @VisibleForTesting or can use reflection to individually test those methods.
Adv Java Interview Questions
Adv Java Tutorial
J2EE Interview Questions
JSP Interview Questions
Adobe Photoshop Interview Questions
Hibernate Interview Questions