Questions tagged [mocking]

Mocking and faking are ways to isolate code or components to ensure that unit tests run against the testable unit of code only without actually utilizing other components or dependencies of an application. Mocking differs from faking in that a mock can be inspected to assert the results of a test.

0
votes
0answers
18 views

Mocking image file for react test

I have a component that shows the thumbnail of an image which is uploaded which looks like the following: class Thumb extends Component { state = { loading: false, thumb: undefined, }; ...
0
votes
0answers
16 views

Unable to Mock REST API function with Python Mock in Django

I have an API which use ElasticSearch to get data. I have to write test cases for this. These tests will be run using Circle CI. When we run test cases on test cases on Circle CI, test failed as ...
1
vote
0answers
30 views

Verify mocked method call with lambda?

Using Mockito, I'd like to verify a mocked method call (particularly the parameters passed to it) via a lambda, without having to use a Captor, etc. MyThing class MyThing { public void run() { ...
1
vote
0answers
16 views

How can i mock requests.Session.send() method?

How can i mock it? I have overridden class from requests import Session class MySession(Session): def __init__(self, *args, **kwargs): super(MySession).__init__(*args, **kwargs) ... ...
0
votes
0answers
17 views

How to mocking DbRawSqlQuery<int> result?

I created a method for check that in db has a stored procedure. public class StoredProcedure : IStoredProcedure { private readonly IDbContextProvider<MyDbContext> _dbContextProvider; ...
0
votes
0answers
14 views

How to return nested collection from angular-in-memory-web-api?

I have relational data where the relationship is noted in the URL. As an example, blogs have comments. So my URLs would be: /api/blogs/1 /api/blogs/1/comments I have set up both collections in ...
0
votes
1answer
18 views

Simulate localStorage data in test

I am using Create React App. I am trying to simulate isLoggedIn behaviour in my component to get all lines code coverage. To do that localStorage key: user must exist with data.accessToken I tried ...
0
votes
0answers
14 views

How to mock data from the library in Jest testing?

How should I mock data from the library for jest testing? I have tried jest.mock('apollo-link-http') but not able to mock httpLink from it.
0
votes
1answer
20 views

When trigged action, mockNavigationController return current viewController, not pushed

I learning TTD, and have problem with navigation controller in Unit-testing. When I'm trying to push Detail View Controller through navigation stack (pushViewController(ViewController, animated:) )...
0
votes
0answers
25 views

How to mock individual methods of a SpyBean?

I'm working on a test class where one specific test needs the actual implementation of a method of a service class that I'm mocking. So I thought, why not use @SpyBean instead of @MockBean and use the ...
-1
votes
0answers
29 views

pytest - how can I mock method of third party library?

I am probably missing something with my mock Objects but here is my code. a.py import ldd def mymethod() : a = ldd.lookup().client() ... res = a.commit() ... do things with res I want ...
0
votes
0answers
16 views

Soap UI Mock service for Rest not working when deployed as war

I want to create SoapUI mock service for the endpoint: "/product/123456/details/". Here 123456 is path variable. I have created a soap ui mock service with path as "/product/" and in response I'm just ...
0
votes
1answer
15 views

Mocking session.add and returning primary key which would have been generated by Database table

i am trying to mock sqlalchemy session.add such that when i insert session.add(order) and commit it , it should give me order.orderId back which i will use to extends the test case further . ...
1
vote
1answer
30 views

How do I mock an object being returned from a parent object all on the same call

so this is my line of code in my concrete method: var patron = patronService.GetPatron(new GetPatronRequest() { PatronId = request.PatronId }).Patron; where my GetPatron method returns a ...
-1
votes
0answers
14 views

How to mock a variable whose value is injected using @Value annotation [duplicate]

I have a class with a member variable. It gets its value from properties file using @Value annotation. This variable is then used inside a method. Now i am trying to write unit test for this method. ...
0
votes
1answer
25 views

mock.patch decorator: missing 1 required positional argument: 'self'

I am trying to patch a variable in module settings during a test method run: from unittest import mock class Test(...): @mock.patch('settings.TARGET_SCORES_PER_SECTION', True) def ...
0
votes
0answers
22 views

Junit: injecting a dependency

I was facing an issue regarding injecting dependencies in a class. Class A had a dependency, B, which is annotated with @Autowired. B class is itself annotated with @Service In unit test for A, ...
0
votes
0answers
26 views

How to fake indirectly called functions of a Typescript namespace?

Assume the following namespace is given: export namespace CodeUnderTest { export function A(): void { B(); } export function B(): void { console.log("B was called."); ...
0
votes
0answers
12 views

Minitest returns NoMethodError any_instance for JSON:Module

I've been stubbing things fine in Rails5 using mocha and minitest, including custom classes and Net/*. However, I'm now trying to raise JSON::ParserError and I'm getting NoMethodError: undefined ...
1
vote
1answer
41 views

How can I use Moq here?

My WEB API project is using a Generic Repository that implements an interface like this: public interface IGenericEFRepository<TEntity> where TEntity : class { Task<IEnumerable<...
0
votes
0answers
10 views

Function test using Promise and fetch

Trying to run a test using Jest and Enzyme for a function. Function is not being called inside of any onClick or onChange event Here is the function : patchSourceEntity = () => { return new ...
0
votes
0answers
25 views

JSON Server db.json structure

I'm using JSON Server to mock the REST API for React application. I have the following mock data structure { "foos": { "id": 1, "content": "foo", "bars": [1] }, "bars": { "...
0
votes
0answers
21 views

AttributeError: 'DockerVolume' object has no attribute 'volume'

I have running the unittest , in that from another function variable it is used in a function.So while mocking that i'm getting error I'm getting error while executing the unittest for below code.For ...
0
votes
1answer
18 views

How can I return multiple answers in sequential calls to a mocked static method

I have a function that returns the value of java.net.InetAddress.getLocalHost().getHostName() I have written a test for my function like so: @PrepareForTest({InetAddress.class, ClassUnderTest.class}...
0
votes
0answers
9 views

Cannot mock Vue.prototype with ts-jest

Greetings overflowers, I am trying to create a strongly typed mock of Vue using mocked of ts-jest like this const MockedVue = mocked(Vue) However my IDE still cannot recognize MockedVue.prototype ...
0
votes
0answers
34 views

ActiveRecord scope invocation test

I want to test/find out whether particular scope in my active record model was invoked during code fragment execution. The standard way to check that via ModelName.expects(:method_name).once does not ...
1
vote
1answer
21 views

What is the correct way to create a stub/mock for the Scheme property present under Uri in Rhinomocks

I'm writing a Unit Test case for a c# method with the help of Rhinomocks framework. Inside my actual method I access the Scheme property from the Uri property present under System.Net.Http....
0
votes
1answer
41 views

How to mock a pika connection for a different module?

I have a class that imports the following module: import pika import pickle from apscheduler.schedulers.background import BackgroundScheduler import time import logging class RabbitMQ(): def ...
3
votes
2answers
18 views

How do I mock a a file IO so that I can override the name attribute in a unit test?

I'm trying to write a unit test mock opening a file and passing it into a function that uses it to dump a JSON object into. How do I create a fake IO object that mimics the behavior of an open file ...
0
votes
0answers
11 views

Jest: Mocking files with different names

I have a file named foo.js that I want to mock, and instead of naming this file foo.js in the __mocks__ folder, I am wanting to name it foo.mock.js. How can I do this with jest? Thanks! | - foo.js | -...
0
votes
0answers
41 views

How to raise an error when testing a function in Python

I'm trying to do a very simple test where my function takes in one parameter, a path to a database, tries to connect to the database using pyodbc.connect(database path) and if the path is invalid ...
0
votes
1answer
13 views

Mock a nested function with input arguments in Python

My folder structure main.py class Class1 generate_columns() column_api() utilities.py class Class2 get_response() I want to mock column_api() function in class Class1....
0
votes
0answers
13 views

Issue Raising Events with Mocking

I have a Test method which tests for DataGridView Event by using Mocking and Raise event. However it keeps giving me the following error: Can not instantiate proxy of class: System.Windows.Forms....
0
votes
0answers
12 views

JSON-Server index.html

I'm using JSON-server to mock the backend for React application. I need to apply custom middleware for the /index.html path which is used for CSRF token retrieval by the application. I tried the ...
1
vote
1answer
24 views

How do you properly mock objects in unity without using interfaces?

I'm trying to find a way for mocking objects without creating interfaces ( my boss told me so) but so far the only way I found is to actually create a new monobehaviour with fake methods in it and run ...
0
votes
1answer
33 views

Equivalent of doReturn(x).when(y)… in mockk?

I am looking for a mockk equivalent of doReturn(...).when(...).* I am working on writing some unit tests (testing contracts) that involves a lot of system classes and so need to intercept the methods ...
0
votes
0answers
14 views

Issue about mocking PDO class

Inside the setUp() function I want to use the PDOMock class, defined as follow namespace TddProject; class PDOMock extends \PDO { public function __construct() {} } But when I run the test I get ...
0
votes
1answer
7 views

Android check if app is selected for mocking location

my app uses mocking location, so I want to check, if my app is selected in the dev settings. Since ALLOW_MOCK_LOCATION is deprecated, I can not find how to do it. There must be a similar setting, that ...
0
votes
1answer
33 views

Is there a way of mocking an API request by default if you are in a test environment using Laravel?

I have an API method that is called by clicking a buttom in a form and inside that API method there is a request to another API of another project using guzzle. That works fine. My problem is I'm ...
1
vote
0answers
29 views

Mocking aggregate classes

we have the following method inside class C: public static void m(a A, b B) { ...... A1 a1=new a.getA1; //Not sure about the syntax Double d1= a.getInfo; ..... if (d1>5.0) { b.add(d1,a1) ...
0
votes
1answer
22 views

mock and side_effect substitution - keeping access to the original class and its attributes

I want to mock method _subprocess on a particular instance of a class. Specifically when the task fires off pip freeze as a command (in that case its taskname is freeze). class Command(object): ...
0
votes
0answers
19 views

How to mock sealed classes with mockk?

I am trying to mock a sealed class which looks something like this: sealed class Location class Home: Location{ val name ="Home" } I would like to be able to do the following: val mockHome = ...
-1
votes
0answers
28 views

How to inject different service implementation when unit testing

Hello i have ASP NET Core application on which i am writing unit tests.Is there any way to inject a service implementation when testing and another one when normal usage? Example: public interface ...
0
votes
1answer
29 views

Overriding linking in Cpp to point to mocked implementation

I need to mock some classes using GoogleMock and change the base class implementation so that it creates actually an instance of this mocked one. The base class is generated automatically along with ...
0
votes
2answers
24 views

How to send parameters to mock function?

I have two functions. Function function2() call function1(). Original function1() get one value from parameter and return one value. I want to test the function2() with mock function1(). But mock ...
-1
votes
0answers
34 views

How to pass argument(another function) to mock function in google mock?

Trying to mock a function which takes in another function as a parameter. Trying to test dynamic binding. Not sure if there is a way to test. But when I tried I am getting the following error, ...
0
votes
1answer
39 views

In C# Unit test how do equivalent of Java's Spy (instead of Mock) to only mock some methods on a class?

In Java, when I have a class that calls some other class' static method, I always encapsulate this so I can test it without actually hitting that real resource. For example: public class ...
1
vote
1answer
13 views

how to mock a file object in python3

In python2 I have this in my test method: mock_file = MagicMock(spec=file) I'm moving to python3, and I can't figure out how to do a similar mock. I've tried: from io import IOBase mock_file = ...
0
votes
0answers
6 views

test my final javascript library with mocked document

We have our JS library we add to pages, then the script adds another script, creates an iframes and listen for messages from the iframe. So the library interacts with the document object for ...
0
votes
0answers
4 views

Machine.Fakes - Return a different value the second time a mocked method is called

just wondering if anyone knows if it is possible to return a different value the second time a mocked method is called using MSpec Machine.Fakes, I cant seem to find any documentation on this. I know ...

http://mssss.yulina-kosm.ru