Category "mocking"

How can I mock dependencies which aren't interfaces but subclasses?

I'm not sure if my design is simply stupid, or there's a good way to make it work. Consider the following classes: public abstract class CheckBase { protect

How do I mock a static void method (not with doNothing or invocation -> null) using Mockito.mockedStatic?

I have the following classes class FileDownloader { public static void downloadFile(String repoUrl, String filename) throws IOException { // Downloa

Mock patch specific instance of class

How to mock a specific instance of a class using patch? In my test file I have: @classmethod def setUpClass(cls): cls.instance_of_my_class = myClass() one

error when Add a stub for a method using Mockito's 'when' API

Have this abstract class to get data from remote data source abstract class NumberTriviaRemoteDataSource { /// Calls the http://numberapi.com/{number} endpoin

What is the best practice to Mock the whole API

Input: We have API-A and API-B. API-A sends some requests to API-B and do some work with received data. We have unit tests that verify work of methods that doin

How do I mock boto3's StreamingBody object for processing with BytesIO in Python?

I'm unittesting a function that transforms an element from an S3 object into a pandas DataFrame and need to mock the returned StreamingBody object from boto3 f

Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work

I have to test the routes of a controller which uses Guzzle Wrapper as a client to get data from an API. The app uses Laravel as a framework. This is the part o

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