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.

PowerMock testing - set static field of class

I'm having difficulty finding a way to set a static field of a class. It's basically like this: public class …

junit static mocking powermock
Mockito: How to easily stub a method without mocking all parameters

I have a method i'd like to stub but it has a lot of parameters. How can i avoid mocking …

java unit-testing mocking mockito stubbing
How do I mock the HttpContext in ASP.NET MVC using Moq?

[TestMethod] public void Home_Message_Display_Unknown_User_when_coockie_does_not_exist() { var context = new Mock<HttpContextBase>(); …

c# asp.net-mvc mocking moq httpcontext
Mocking Apache HTTPClient using Mockito

I'm trying to mock Apache HttpClient Interface in order to mock one of its methods mentioned below to return a …

java mocking mockito apache-httpclient-4.x
How do I use Moq to mock an extension method?

I am writing a test that depends on the results of an extension method but I don't want a future …

c# mocking moq extension-methods
How to test a mocked JNDI datasource with Spring?

I am fairly new to Spring and wondering how to create JUnit tests that use a mocked datasource and how …

spring testing junit mocking datasource
Moq mock method with out specifying input parameter

I have some code in a test using Moq: public class Invoice { ... public bool IsInFinancialYear(FinancialYearLookup financialYearLookup) { return InvoiceDate >= …

c# mocking moq
Mocking Java enum to add a value to test fail case

I have an enum switch more or less like this: public static enum MyEnum {A, B} public int foo(MyEnum …

java unit-testing enums mocking code-coverage
What is the purpose of mock objects?

I am new to unit testing, and I continously hear the words 'mock objects' thrown around a lot. In layman's …

unit-testing mocking
Comparison between Mockito vs JMockit - why is Mockito voted better than JMockit?

I'm investigating which mocking framework to use for my project and have narrowed it down to JMockit and Mockito. I …

java unit-testing mocking mockito jmockit