Questions tagged as 'mockito'

1
answer

Error using Mock: Wanted but not invoked: Actually, there were zero interactions with this mock

I am making a list of exercises and I am in doubt about the following:    Exercise 3 - The verify method, from the org.mockito.Mockito.verify package, is   used to check the amount of times a method is invoked.   Add in the ATest class a test...
asked by 01.04.2018 / 05:23
3
answers

How to test the Service layer in a web service application, using mockito and junit

I have a class of services that will receive a dependency injection of an object responsible for the persistence layer. In this service class are all my methods that will respond to the REST call of the web service. The problem is: I would...
asked by 06.09.2014 / 17:12
0
answers

How to make a mock in an android class at runtime?

I'm having a hard time testing, I was wondering if there is a possibility to simulate a custom return in a runtime method example: @RunWith(JUnit4.class) public class TesteSmile { UserAndPass userAndPass = new UserAndPass(); @Rule...
asked by 07.08.2018 / 19:14
2
answers

Test a void method with mockito

How to test a void method with mockito? This is the basic syntax for a return method when(Classe.metodo()).thenReturn(variavelRetorno); However, how do I test a void method?     
asked by 08.07.2016 / 21:10
1
answer

How to return the value according to the received parameter?

I needed to do mocking with DAO, but the method receives a worksheet object and according to the id attribute of the Worksheet needs to return a different value. How do I compare the worksheet ID correctly? I want to test the readMeta...
asked by 26.05.2015 / 20:42
1
answer

How to perform tests on private methods using Mockito

This weekend I read about Mockito and trial stunts, and the following idea came to me. Test private methods with this framework. I see that PowerMock performs this procedure, but has anyone tried to do this using Mockito...
asked by 18.08.2014 / 15:31
1
answer

Mockito - Function that receives jsonObject return false

public class ParseProcessoTest { private final String PATTERN_DATA_HORA = "yyyy-MM-dd HH:mm:ss"; JSONObject jsonObject = new JSONObject("json qualquer"); JSONObject jsonMov = new JSONObject("json qualquer 2"); ParseProcesso parseP...
asked by 23.10.2017 / 15:54
1
answer

Mockito-Android Test method return

I am trying to test a return from a method of my class in an Android project. I'm doing it this way: MyClass var = Mockito.mock(MyClass.class); With this, I already have my instance. Now I need to test methods of this class, I did it this w...
asked by 14.01.2015 / 21:50
1
answer

Mockar non-static method of a class containing a call from another static method

Hello, The title was a bit confusing, but come on. I have the class below: public class ClasseA { public static final int constA = ClasseB.metodoB(); public int metodoA(){ System.out.println("Passei no metodo A");...
asked by 15.01.2018 / 11:41
1
answer

Mock of a class that has parameters in the constructor

public class ParseProcessoTest { private final String PATTERN_DATA_HORA = "yyyy-MM-dd HH:mm:ss"; JSONObject jsonObject; @Mock ParseProcesso parseProcesso; @Before public void init(){ jsonObject = new JSONObject("string qualquer"); when(...
asked by 19.10.2017 / 13:38