Most voted "mockito" questions
Mockito is a framework written in Java that allows you to record readable unit tests (which produce clear verification errors) with a clean and simple API.
Learn more…30 questions
Sort by count of
-
13
votes2
answers1652
viewsHow to perform TDD on the Service layer
I participate in a project that uses MVC layers with Hibernate framework persisting in a Postgres. Junit is used for testing and Mockito is used for mocking (I still have no knowledge and practice…
-
5
votes1
answer3287
viewsError using Mock: Wanted but not Invoked: Actually, there Were zero interactions with this mock
I’m making a list of exercises and I’m having doubts on the following: Question 3 - The Verify method, from the org.mockito.Mockito.Verify package, is used to check the amount of times a method is…
-
4
votes3
answers1850
viewsHow to test the Service layer in a web service application, using mockite and junit
I have a class of services that will receive a dependency injection from an object responsible for the persistence layer. In this service class are all my methods that will answer the web service’s…
-
4
votes0
answers207
viewsHow to make a mock in an android class at runtime?
I am having a certain difficulty in the tests, I wanted to know if there is a possibility to simulate a custom return in a method at runtime example: @RunWith(JUnit4.class) public class TesteSmile {…
-
3
votes3
answers5014
viewsTesting 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?…
-
2
votes1
answer200
viewsHow to return the value according to the received parameter?
I had to mock with DAO, but the method receives a spreadsheet object and according to the id attribute of the Spreadsheet I need to return a different value. How do I do this to correctly compare…
-
1
votes1
answer1739
viewsHow to perform tests on private methods using Mockito
this weekend I read about the Mockito and double tests, and I came up with the following idea. Test private methods with this framework. I saw that the PowerMock performs such a procedure, but…
-
1
votes1
answer422
viewsMockito-Android Test return method
I’m trying to test a return of a method from my class on 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…
-
1
votes1
answer662
viewsSpring boot test - Junit
How do I resolve this problem and run the Junit test on Spring boot? @RunWith(SpringRunner.class) @SpringBootTest @ActiveProfiles("test") @ContextConfiguration(classes = { CategoriaTest.class,…
-
1
votes0
answers124
viewsJava - When(). Thenreturn() Mockite Function
@Mock RequestUtils requestUtils; @Before public void init() throws IOException, ClassNotFoundException { MockitoAnnotations.initMocks(this); HtmlPage paginaPesquisa =…
-
1
votes1
answer476
viewsMock 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 =…
-
1
votes1
answer181
viewsMockito - 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…
-
1
votes1
answer587
viewsMock non-static method of a class containing a call from another static method
Hello, The title got a little fuzzy, 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…
-
1
votes1
answer189
viewsfunction equals of object is not called during unit test
I’m developing unit test of a class with Junit and Mockite, and to facilitate the creation of a spy of this class I created a function that builds and returns this spy. The problem that is occurring…
-
1
votes1
answer334
viewsHow to create a unit test using mockite in a list of objects
I know exactly what I need to mock about the object data, but I have no idea how to implement a test when it comes to a list of objects, I just need an example, someone could only show me an example…
-
1
votes0
answers41
viewsHow to mock a method that has varargs as arguments?
I would like to mock this method: @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public List<E> buscarTodos(String ... sorting) { Sort sort = null; if (sorting…
-
1
votes1
answer705
viewsUnit Test Controller Spring with Mockito
I’m trying to test the method below my controller: @RequestMapping(value = "/listar", method = RequestMethod.GET) public ModelAndView iniciaTela(ModelAndView model, HttpServletRequest request){…
-
1
votes1
answer315
viewsUnit test (Junit and Mockito) - Clean & maintainable test code requires zero unnecessary code
I am writing the test of a findByID method(): public DoctorDTO getDoctorById(long id) throws DoctorNotFoundException { Optional<Doctor> doctorO = VerifyIfExists(id); return…
-
1
votes1
answer24
viewsError in using Mockito. Actually, there Were zero interactions with this mock
I am trying to do a check but for some reason the test is not passing. I have no idea why. Follow the error shown: Actually, there Were zero interactions with this mock. Follows the code: public…
-
0
votes0
answers26
viewsAndroid does not recognize Mockito Noclassdeffounderror
I’m trying to use Mockito to perform tests on an Android app. I copied the following jars for the project: Mockito-all-1.9.5.jar, dexmaker-1.0. jar, dexmaker-Mockito-1.0.jar. Then I added it to…
-
0
votes1
answer153
viewsModelling View Controller Unit Test with Mockite and Spring
I need to mount the unit test for the controller below (for example only): import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.GetMapping; import…
-
0
votes1
answer324
viewsjava.lang.Assertionerror: Expected: not null but: was null - Junit test
The variable result is returning NULL although the Object is filled. This is my test; @RunWith(MockitoJUnitRunner.class) public class IndicioDAOTest { @Mock private IndicioDAO indicioDAO; @Test…
-
0
votes0
answers77
viewsMockito with Nativequery
need to test a method that uses Native query. However on line Query q = em.createNativeQuery(strQuery, Projeto.class); No value is assigned to q and it is null. Can someone help me? It follows the…
-
0
votes1
answer481
viewsMock local variable inside method with mockite and spring boot
I’m trying to simulate the return of a method on a local variable, but it’s always null, showing java.lang.Nullpointerexception I have the following code within a @service: @Service…
-
0
votes0
answers28
viewsAndroid Unit Test -> Problems mocking a method that has static class
I am doing unit tests of my Viewmodel and have a method that saves the data in Firebase generating an id internally with the help of the Base64 class. In my class structure I call the…
-
0
votes1
answer118
viewsInstantiate Dependency Injection Class using Kotlin in Unit Tests
I’m trying to find a solution for how I can instantiate a class that uses dependency injection into unit testing using Kotlin and Junit. I have a class that uses addiction injection: class…
-
-1
votes1
answer251
viewsMockito returning null Spring Boot + Junit + org.mockito.Bddmockito
Everything all right, guys? At the time I make a mock my error application and returns null of the mock, I have tried several ways to resolve, but it does not send anything different, could help me?…
-
-1
votes1
answer29
viewsUsing Instrumentation Testing to Validate Layout on Android
People, Before asking my question, below is an example of instrumentation code (incomplete purposely) on Android: import android.content.Intent import androidx.lifecycle.Lifecycle import…
-
-1
votes1
answer14
viewsClassnotfoundexception in Java mockite testing
Hello, When testing a class using Mockito, I came across the "Classnotfoundexception" error. Unfortunately I cannot resolve this error. All my dependencies are installed, but the error persists.…
-
-2
votes1
answer658
viewsHow to mock a private function in Junit
I have a main class Usuario extending (extends) an abstract class called Sessao, and uses a function of Sessao calling for obterDados() that takes session data and returns to an object SessaoTO. I…