Category "mocking"

Using scalamock: Could not find implicit value for evidence parameter of type error

I am writing unit tests for my spark/scala application. I am using scalamock as well to mock objects, specifically Session / Session Factory. In one of my test

How to get the arguments passed to various calls from call_args_list?

I'm trying to use call_args_list to get the arguments passed to a certain function when it is called multiple times. I'm using this: call_args_list = mock.add_

How to change mock implementation on a per single test basis [Jestjs]

I'd like to change the implementation of a mocked dependency on a per single test basis by extending the default mock's behaviour and reverting it back to the o

TypeError: (0 , _axios.default) is not a function when use jest.mock('axios') inside a *.test.js file

I try to mock axios module inside my test file like this // mycomponent.test.js import axios from 'axios'; jest.mock('axios', () => ({ get: jest.fn(() =&

TypeError: (0 , _axios.default) is not a function when use jest.mock('axios') inside a *.test.js file

I try to mock axios module inside my test file like this // mycomponent.test.js import axios from 'axios'; jest.mock('axios', () => ({ get: jest.fn(() =&

Is it possible to mock a function imported from a package in golang?

I have the following method to test, which uses a function imported from a package. import x.y.z func abc() { ... v := z.SomeFunc() ... } Is it

Is there a way to set custom responses from an external server when a specific request receive?

I have a program that is only displaying bug behavior when a certain response is received from an external server. The only thing is, the external server is in

Create class and auto-initialize dependencies with FakeItEasy

Is it possible to create a class under test with FakeItEasy, where all dependencies that are declared in the constructor are initialized automatically with fake

How to use MockRestServiceServer with multiple URLs?

I need to configure multiple expectations on an instance of MockRestServiceServer. The expectations are for two different URLs: Call URL #1 Call URL #1 (for a

How to mock IConfiguration.GetValue

I tried in vain to mock a top-level (not part of any section) configuration value (.NET Core's IConfiguration). For example, neither of these will work (using

Angular Mock ActivatedRoute using Snapshot and ParamMap

I'm using this, from here: constructor(private heroService: HeroService, private activatedRoute: ActivatedRoute) { } ngOnInit() { const heroId = this.

How to mock function on unit test actix web

I have an api service that has 2 layer: api and repository. The api layer is where the request handling and business logic defined, while repository is a databa

How to mock Base64 in Android?

I am writing a Unit test for a class that uses android.util.Base64 and I get this error: java.lang.RuntimeException: Method encode in android.util.Base64 not m

How can I configure Moq to return new instance per call?

I am trying to write a simple test with moq. When calling the mocked method for the second time, after changing the return value from the first call, the moq fr

How to set up a stub and assigning a webresponse with Rhino mocking

I'm completely new to Rhino Mocks and mocking in general. I'm still wrapping my head around how to code the mocks. I have a test class which contains something

How to mock a local variables using mockito/powermock

I have a function as follows : private Response getHttpResponse(String url) { WebTarget target = client.target(url); Invocation.Builder requestBuilder =

Mockito ClassCastException - A mock cannot be cast

I have a method in the class AppleProcessor which I would like to test: public void process(Fruit fruit) { if(fruit.getType() == Fruit.APPLE) { fru

@patch decorator cannot set Provider

I tried patching a provider class by decorating a test method with @patch: class TestMyUnit(unittest.TestCase): ... @patch(provider.Provider,autospec=True) def

FastAPI: app.dependency_overrides affects other test files

I'm working with FastAPI. I've introduced in my test suite (pytest) app.dependency_overrides to test my app dependencies. Strangely enough, when I use it in a t

Best approach to mock hiredis library in C

I am writing a project that takes advantage of the hiredis redis client library. What is the best approach to mock this library for use in writing tests? For