Most voted "mock" questions
31 questions
Sort by count of
-
35
votes2
answers9074
viewsWhat is the difference between mock & stub?
In what situations should be used? What’s the difference between them?
-
12
votes2
answers377
viewsOverride the Python mock Decorator
I have a class TestCase where all tests, except one, need to patch the same object. I am using the Python Mock, and I did the following: @mock.patch('metodo_alvo', mock.Mock(return_value=1)) class…
-
10
votes1
answer247
viewsWhat are the differences between mocks and fakes?
When we implement tests in software, Mocks and Fakes are two techniques or approaches to isolate the code being tested from the rest of the system. Without going into it: Mocks are like empty shells…
-
9
votes2
answers2071
viewsWhen to use static methods mock?
@Fernandoschelb recently asked the question about how to mock static methods. It raised my doubts: If we can do it, when we should do it? What are the cases where static method mock is beneficial?…
-
6
votes2
answers944
viewsMock Static method with Demoiselle and Powermock/Mockito
I’m trying to mock a Static method, but Powermock requires the use of a specific Runner (Powermockrunner) for the Static mock to work! And for Demoiselle to work, you need to start Weld with…
-
6
votes3
answers993
viewsHow to simulate JSON responses?
I need something that simulates JSON responses for me. A while ago I had seen a site that did the following: You pass parameters through a URL, e.g.: ?nome=Wesley&idade=21 Received in the call…
-
5
votes1
answer228
viewsAvoid removing the Testprovider from Mock Location
I am trying to mock location for use in another application, but this application is removing my Testprovider, making it not possible to mock the location. How can I avoid this other app from…
-
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
votes1
answer127
viewsMock a raw_input
I have the following functions with raw input, which should receive a list [x,y] def input_origem(): origem = raw_input("Entre com o valor de x: ") origem = eval(origem) return origem def…
-
3
votes1
answer1776
viewsUnit test/ Mock of a JPA query
Hello, how do I generate a unit/mock test of a JPA/Criteria query ? What can I guarantee by mocking my objects? Table structure? What should I mock? The consultation is very simple, only one select…
-
3
votes2
answers229
viewsCheck data according to the ready information
I would like to make this form check the following data by clicking "Confirm" and if any of them is correct it will go to the next page. MOCK: $scope.cliente = [{ nome: "nomeedit", senha:…
-
2
votes0
answers125
viewsHow to create a Mock in Ruby On Rails (Carrierwave) to simulate sending an image to a S3 (Cloudinary)
I created a project creation system with image. My images are uploaded to Cloudinary + Carrierwave. Before the Test did not break because I sent to the server, but when I integrated in Cloudinary…
-
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
votes0
answers99
viewsTest API Python
How can I test an api url using nosetest for example: I have the following api: /api/user how to ensure that calls at this url are being called? make a GET... one POST passing the parameters on the…
-
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
answers238
viewsPytest-mock fixture configuration
I would like to do tests using pytest-mock. I have already run the Pip install pytest-mock command and installed it, but when I run the test below pytest can’t find the fixture. What can be? import…
-
1
votes0
answers275
viewsProblem when performing a test with POST method
I’m trying to run a unit test of the post method, but the system returns the Status expected <200> but was <404>. If I use the postaman with the Json I’m creating in Java, it returns the…
-
1
votes0
answers71
viewsMoq in c# methods of different classes
Good night. I’m new to unit testing. I’d like to ask for help to resolve a question. I have the following method of a class that calls the method of another class: class public Teste: ITeste {…
-
1
votes1
answer37
viewsHow to create a test for a screen that uses the same hook multiple times? React Testing Library
I came across a test scenario in React where I need to hook twice. In this case I am using a hook called useGet() in two situations on the same page. Of all the times I have tried only the last…
-
1
votes1
answer67
viewsHow do I test integration with mock from React?
I want to test the following component but I don’t know how to use jest mocks in case of a request with Axios. Component: import React, { useEffect, useContext } from 'react' import {…
-
0
votes1
answer27
viewsunittest.mock: How can I use datetime.datetime.now with different calls in the same method?
How can I proceed with a mock test on datetime.datetime.now with different calls in the same method? In my test is returned the current date. Follow an example of the code, to facilitate help.…
-
0
votes1
answer33
viewsClass mock without methods
I need to mock a class that has no methods and returns nothing, how could I do that in Python? I’m mocking this class because it acts as a typing converter. My class is very similar to the one…
-
0
votes1
answer95
viewsHow to mock a nonexistent class with Rspec Mock
I’m creating a lib that will use a model pattern of Rails, only that for the development of this lib I need to test without the presence of this model. So think about mocking (I’m using Gem…
-
0
votes0
answers94
viewsHow to perform unit test with unittest.mock for reading and writing files?
Good Night!!! This time my doubt is about unit tests. Come on. How can I test the section below in unittest.mock environment? def save_html_file(conteudo, filename, encoding='iso8859-1'): assert…
-
0
votes1
answer32
viewsPython: How to apply mock in dataclass?
I have following code : import unittest import unittest.mock as mock from dataclasses import dataclass @dataclass class Config: system: str = platform.system().lower() class…
-
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
votes1
answer31
viewsApply filter to a list returned by a mock
Good night! I have the following scenario: A concrete class called Usersservice, which receives by injection of dependencies the repository through an interface and a notifier. She gets like this…
-
0
votes0
answers18
viewsjest mockImplementation does not work in React navigation (React Nactivate)
I have the following code: jest.mock('@react-navigation/native', () => { return { useNavigation: mockedNavigation, }; }); ... it('should pass the test', async () => {…
-
-1
votes1
answer49
viewsMock and inject a service class at the same time
I have a spring test class that in some cases I want it to behave in the normal flow, that is, when it is done a findAll() hitting the repository it returns the value it selects from the embedded…
-
-1
votes0
answers8
viewsasynchronous import to jest.mock to keep the simulation file separate and reusable for other tests
I am trying to make an import into my play simulation to use a separate file to play the same simulation in multiple codes. Simulation below: const listCache: Array = []; jest.mock('aws-sdk', ()…