Mock HttpContext.Current in Test Init Method

I’m trying to add unit testing to an ASP.NET MVC application I have built. In my unit tests I use the following code: [TestMethod] public void IndexAction_Should_Return_View() { var controller = new MembershipController(); controller.SetFakeControllerContext(“TestUser”); … } With the following helpers to mock the controller context: public static class FakeControllerContext { public static HttpContextBase FakeHttpContext(string username) … Read more

Unfinished Stubbing Detected in Mockito

I am getting following exception while running the tests. I am using Mockito for mocking. The hints mentioned by Mockito library are not helping. org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: -> at com.a.b.DomainTestFactory.myTest(DomainTestFactory.java:355) E.g. thenReturn() may be missing. Examples of correct stubbing: when(mock.isOk()).thenReturn(true); when(mock.isOk()).thenThrow(exception); doThrow(exception).when(mock).someVoidMethod(); Hints: 1. missing thenReturn() 2. you are trying to stub a … Read more

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 mock a function def foo(self, my_param): #do something here, assign something to my_result return my_result Normally, the way to mock this would be (assuming foo being part of an object) self.foo = MagicMock(return_value=”mocked!”) Even, if … Read more

Mocking Extension Methods with Moq

I have a preexisting Interface… public interface ISomeInterface { void SomeMethod(); } and I’ve extended this intreface using a mixin… public static class SomeInterfaceExtensions { public static void AnotherMethod(this ISomeInterface someInterface) { // Implementation here } } I have a class thats calling this which I want to test… public class Caller { private readonly … Read more