Category "mocking"

How do I mock a function with no parameters that sets a class attribute for Python unit tests?

My class, Foo, has a calculate method that takes no parameters, makes a call to a database and does some calculations using class attributes, and sets another c

Is there an equivalent of verifyZeroInteractions() for verifying an exact number of interaction with a mock object?

I would like to verify there were exactly x interactions with might db mock object. Is there something similar to the 'verifyZeroInteractions()' method for doin

Assert mock call with argument assigned in where block in Spock

I have a method that among others generates an identifier, sends it to some external dependency and returns it. I want to have a unit test that tests if the sam

Use a MagicMock as its own return value?

Normally, a MagicMock returns new MagicMocks for any attribute or method called on it: >>> mm = MagicMock() >>> mm <MagicMock id='14009455

Use a MagicMock as its own return value?

Normally, a MagicMock returns new MagicMocks for any attribute or method called on it: >>> mm = MagicMock() >>> mm <MagicMock id='14009455

Symfony 5.2 mock service disappear in second request

I used Symfony 5.2 and I need to mock service method which execute send request to stripe payment system, obviously don't need to execute it when tests executin

Symfony 5.2 mock service disappear in second request

I used Symfony 5.2 and I need to mock service method which execute send request to stripe payment system, obviously don't need to execute it when tests executin

How to use mock_open with json.load()?

I'm trying to get a unit test working that validates a function that reads credentials from a JSON-encoded file. Since the credentials themselves aren't fixed,

python: clear / reset `@lru_cache` functool caching with every pytest testcase for undisturbed mocking

I combine mocking and caching in my code. The mocking is (kind of) random for each pytest as I do not know exactly, what will be returned in the real case. Henc

Concise RAII for Trompeloeil mocks

I have classes like this: /* "Things" can be "zarked", but only when opened, and they must be closed afterwards */ class ThingInterface { public: // Open the

Mock a Widget in Flutter tests

I am trying to create tests for my Flutter application. Simple example: class MyWidget extends StatelessWidget { @override build(BuildContext context) {

How do I set or freeze time in python?

I want to set a fixed time using python different than that seen locally on my system , so that when I used datetime.date.today() I get to see the desired date

How to mock Spring WebFlux WebClient?

We wrote a small Spring Boot REST application, which performs a REST request on another REST endpoint. @RequestMapping("/api/v1") @SpringBootApplication @RestC

How to mock redis connection in Go

I am using https://github.com/go-redis/redis package to make Redis DB calls. For unit testing I want to mock these calls, is there any mock library or way to do

Jest: Better way to disable console inside unit tests

I wonder if there is a better way to disable console errors inside a specific Jest test (i.e., restore the original console before/after each test). Here is my

Test function with lru_cache decorator

I'm attempting to test a a method that is memoized through lru_cache (since it's an expensive database call). with pytest-mock. A simplified version of the cod

how to prevent jdbc from trying to connect to a mysql database during unit testing

I'm making an application for a school project, but I'm running into the issue that when I try to run the unit tests that it tries to connect to the database wh

Jest 27: How to reset mock for jest.spyOn(window, "setTimeout")?

I am updating a project from jest version 26 to jest version 27. As part of the update I had to switch from assertions on setTimeout to assertions on jest.spyOn

Mocked values mismatch with MagicMock

I am working on a python project, where we read parquet files from azure datalake and perform the required operations. We have defined a common parquet file rea

How to Mock the Request Class in Laravel?

I'm trying to test a function that depends on $request->all(); in a method. How do I mock the Request class so $request->all(); returns ['includes' =