Testing - Interview Questions and Answers for 'Mockito' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Testing - Interview Questions and Answers for 'Mockito' - 17 question(s) found - Order By Rating

 Q1. How do you mock private methods using Mockito ?Mockito
Ans. We just declare the methods as protected and mark them with the annotation @visibleForTesting

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q2. Can we mock private methods ?PowerMock
Ans. Yes, using Power Mock.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     mockito  mocking  testing


 Q3. Does it make sense to mock integration calls during stress / load test ?Testing
Ans. No, its usually not done.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     integration testing  stress testing  mocking  Mockito


 Q4. What is doCallRealMethod() method used for ?PowerMock
Ans. When we Mock an object and then make a reference to any method using mocked object reference , java never makes a call to that method and looks for mocked value to be returned or null if none specified. But If we want that to be overridden and want java to make actual method call upon using mocked object reference, this method can be used.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     junit  mocking  java unit testing  Mockito


 Q5. What does the following code

MockitoAnnotations.initMocks(this);
Mockito
Ans. Initializes objects annotated with Mockito annotations

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     mocking  java mocking frameworks  Mockito


 Q6. Have you ever used PowerMock ? If yes , which mocking framework you have used it with ?PowerMock
Ans. Yes, I have used PowerMockito with Mockito.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Mockito


 Q7. Does it make sense to verify a method call if we already have a mock for it.

For example -

Mockito.when(a.callMethod()).thenReturn(1);
verify(a.callMethod()); // Does it make sense
Mockito
Ans. There is no guarantee that the mock will get called as callMethod may never get called. Verify is to make sure that the method gets called. Mock is it return 1 if the method gets called so they both are kind of independent things.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q8. Do you use Mockito's generic any method or just prefer to use specific arguments ?Mockito
Ans. It depends on the data type, we use as the parameter.
If it is a simple data type and we validate the input, we may use specific arguments.
Else, we can go for the generic any

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q9. Can we mock static methods using Mockito ?PowerMock
Ans. No, We can use PowerMock for that.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     mockito


 Q10. How do you use Mock frmaework to test webservices in any of your previous project ?Testing
Ans. We were having client methods to call web services and were mocking the client method call using Mockito.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     mocking  testing  mockito


 Q11. Can we mock static methods ?Testing
Ans. Yes we can use PowerMock. With Mockito , we cannot mock static methods.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     mocking fraeworks  mocking static methods  mockito


 Q12. Have you ever tried mocking static methods ?Testing
Ans. Yes, that can be done using Power Mock. Mockito doesnt provide a way to mock static methods.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Mockito  junit  powermock     Asked in 1 Companies


 Q13. Difference between Assert and Verify ?Testing
Ans. Assert works only if assertions ( -ea ) are enabled which is not required for Verify.Assert throws an exception and hence doesn't continue with the test if assert evaluates to false whereas it's not so with Verify.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     assert   junit   mockito   verify   testing   unit testing     Asked in 5 Companies


 Q14. What should I do if I want to make sure that a particular method of a class is getting called ?
Ans. If its a static method of the class , we can use verify to make sure its 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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     junit   mockito   mock


 Q15. What is the use of Mockito.any ?
Ans. 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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     junit   mockito   mock   mockito.any


 Q16. What are the steps to be performed while coding Junit with Mocking framework ?JUnit
Ans. Initialize required objects for working with mocks and tested method
Set the mock behaviour on dependent objects
Execute the tested method
Perform assertions
Verify if a method is invoked or not

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     junit   mocking frameworks   mock   unit testing   java   white box testing  Mockito


 Q17. Which of the following is not the advantage of Mocking frameworks ?

a. It helps testing the module independently
b. It helps in faster unit testing
c. It helps in testing code even when external dependencies like service calls are not working
d. It helps in doing end to end Integration Testing
Ans. It helps in doing end to end Integration Testing

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     mocking frameworks   mockito   unit testing   junits



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: