Top "Mocking" questions

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.

moq objects Returns method, should return a null object

I'm developing a Web API, and one of the test I came up with is that, if client makes a …

c# asp.net-mvc-3 mocking moq wcf-web-api
How to mock a readonly property with mock?

How do you mock a readonly property with mock? I tried: setattr(obj.__class__, 'property_to_be_mocked', mock.Mock()) …

python unit-testing mocking pytest
mock or stub for chained call

protected int parseExpire(CacheContext ctx) throws AttributeDefineException { Method targetMethod = ctx.getTargetMethod(); CacheEnable cacheEnable = targetMethod.getAnnotation(CacheEnable.class); ExpireExpr cacheExpire = targetMethod.…

java unit-testing mocking mockito
How to mock an import

Module A includes import B at its top. However under test conditions I'd like to mock B in A (mock …

python mocking python-import
Swagger/OpenAPI mock server

I have an API reference in a Swagger file. I want to create a very simple mock server, so that …

mocking swagger swagger-2.0 openapi
Mocking a global variable

I've been trying to implement some unit tests for a module. An example module named alphabet.py is as follows: …

python unit-testing mocking patch
ASP.NET WebApi unit testing with Request.CreateResponse

I am trying to write some unit tests for my ApiController and faced some issues. There is a nice extension …

c# unit-testing asp.net-web-api mocking httpresponse
Mocking vs. Spying in mocking frameworks

In mocking frameworks, you can mock an object or spy on it. What's the difference between the two and when …

unit-testing mocking tdd
Mocking database in node.js?

How would I mock out the database in my node.js application, which in this case uses mongodb as the …

node.js mongodb unit-testing mocking database
cannot resolve symbol PowerMockRunner

I'm trying to use Powermock for the first time I use build.gradle and added: dependencies { ... testCompile 'org.mockito:mockito-all:1.9.5…

java unit-testing mocking mockito powermock