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.

What is the difference between mocking and spying when using Mockito?

What would be a use case for a use of a Mockito spy? It seems to me that every spy …

java testing mocking mockito
How to mock static methods in c# using MOQ framework?

I have been doing unit testing recently and I've successfully mocked various scenarios using MOQ framework and MS Test. I …

c# unit-testing mocking moq
Mocking methods of local scope objects with Mockito

I need some help with this: Example: void method1{ MyObject obj1=new MyObject(); obj1.method1(); } I want to mock obj1.…

object mocking local mockito
How to check JSON in response body with mockMvc

This is my method inside my controller which is annotated by @Controller @RequestMapping(value = "/getServerAlertFilters/{serverName}/", produces = "application/json; charset=…

java spring junit mocking spring-test-mvc
Creating a mock HttpServletRequest out of a url string?

I have a service that does some work on an HttpServletRequest object, specifically using the request.getParameterMap and request.getParameter …

java mocking servlets
How do I mock a static method that returns void with PowerMock?

I have a few static util methods in my project, some of them just pass or throw an exception. There …

static mocking mockito void powermock
Mocking python function based on input arguments

We have been using Mock for python for a while. Now, we have a situation in which we want to …

python unit-testing mocking mockito
Mocking a method to throw an exception (moq), but otherwise act like the mocked object?

I have a Transfer class, simplified it looks like this: public class Transfer { public virtual IFileConnection source { get; set; } public …

c# unit-testing mocking moq
Trying to mock datetime.date.today(), but not working

Can anyone tell me why this isn't working? >>> import mock >>> @mock.patch('datetime.date.…

python testing datetime mocking
Mock functions in Go

I'm puzzled with dependencies. I want to be able to replace some function calls with mock ones. Here's a snippet …

unit-testing mocking go