mocking

How to create a proxy of an interface in Java?

Hello, How can one create a proxy for an interface without creating a class that implements it? I have a concrete example: I have an interface, Contact, and need to create a proxy object that acts as a Contact. This proxy object will be used for running some TestNG tests. I have tried using the JDK approach but could find only example...

Ruby Mash equivalent in Python?

Hi all, in Ruby, there's this awesome library called a Mash which is a Hash but through clever use of missing_method can convert: object['property'] to object.property This is really useful for mocks. Anyone know of a similar kind of thing in Python? ...

Hot to set a richtext box in Pencil (wireframing tool) to a custom width

Hi, I'm creating a prototype with Pencil an open source wireframing and mocking tool. I need to add a rich text box to my prototype and fill it with some sample text. The problem is that the box automatically resizes it self to around 200px and it won't budge from that width no matter what I do. I need to know how to set a custom width...

Mocks: Test for presence/absense of break/return in a block

I'm trying to write out some examples for a Proc that will be passed to a function as a block to be yield'd various values. I'd like to be able to specify that given some inputs, it will just return a value to the function given other values, it will break (or return) a value, skipping the rest of the function's execution. How can ...

Are Using Interfaces Soley to Facilitate Stubing and Mocking in Unit Tests Now Obsolete?

In .NET, TypeMock Isolator and Microsoft Moles allow one to isolate any class, property, or method - be it sealed, static, protected or non-virtual. So what was impossible to mock in Moq or Rhino Mocks, now no longer is the case. I've always had some aversion with the idea of using an interface merely to be able to allow for mocking, wh...

How are both of these tests passing?

I'm using Shoulda, Mocha, and Test::Unit for testing. I have the following controller and test: class FoosController < ApplicationController caches_action :show def show @foo = requested_foo end private def requested_foo Foo.find(params[:id]) end end class FoosCachingTest < ActionController::IntegrationTest def s...

Unit Testing in .Net with Endeca Objects

Most or all of Endeca's objects have internal constructors. I'm working on a good project that lacks great test coverage around the Endeca API, are there any good strategies to unit testing the interactions with Endeca? So far the best we have is kind of a poor man's adapter pattern: public class DimValue : IDimValue { public DimVa...

Silverlight in browser UnitTesting Mock<FileInfo>

Hi All, I'm facing difficulties in Silverlight (inbrowser) UnitTesting using Mock to read a file into my ViewModel. It gives me an AccessDenied error message. Is there another alternative method for that kind of problem? My UnitTesting is DragAndDrop Image file in Silverlight 4. eg: unittesing.cs var fileInfo = new Mock(); ...

Microsoft.Web.Mvc.LinkBuilder.BuildUrlFromExpression failing when testing Asp.net MVC app

So I'm trying to unit-test a controller method. I'm using MSTest in VS 2010, and Moq 3.1 Test method: [TestMethod] public void TestAccountSignup() { var request = new Mock<HttpRequestBase>(); var context = new Mock<HttpContextBase>(); AccountController controller = new AccountController(); ...

Are there free mocking frameworks that can mock methods and classes that are non-virtual, static or sealed?

I know there is TypeMock and JustMock, but both are commercial products and quite expensive. Are there free or open source mocking frameworks that can compete with the two? I am currencly using Moq, but I'm wondering if open source can catch up? Maybe Moles is the answer (http://msdn.microsoft.com/en-us/library/ff798506.aspx), although ...

How can I create and use a partial stub (in MoQ) without being tied to the concrete implimentation?

I have code that uses MoQ to create a partial stub. I'd prefer to interact with the interface instead of the concrete implementation so that I won't have to modify the unit test if I have a different implementation of the interface. So for example, I have a factory method such as: private Mock<ISomeInterface> ISomeInterfaceStubFactory...

How Do I Mock Entity Framework's Navigational Property Intelligence?

Hi Guys, I'm attempting to test my repository using an in-memory mock context. I implement this with an in-memory Dictionary, as most people do. This implements members on my repository interface to Add, Remove, Find, etc, working with the in-memory collection. This works fine in most scenarios: [TestMethod] public void CanAddPost() ...

How should I mock Jersey HTTP-client requests?

This is the class I'm trying to test (it calculates the size of HTTP page): import javax.ws.rs.core.MediaType; import com.sun.jersey.api.client.*; public class Loader { private Client client; public Loader(Client c) { this.client = c; } public Integer getLength(URI uri) throws Exception { return c.resource(uri) // return...

How to mock a method which also belongs to the target class itself?

Let's say we are testing a class C which has 2 methods M1 and M2 where M1 calls M2 when executed. Testing M2 is ok, but how can we test M1? The difficulty is that we need to mock M2 if I'm not misunderstanding things. If so, how can we mock another method while testing a method defined in the same class? [Edit] Class C has no base cla...

Testing Bus.Send in an application using NServiceBus

I have this code in my app .NET application using NServiceBus: Bus.Send<IServiceStarted>(e => { e.ServiceInfo = ReadServiceInfo(); e.EventTime = DateProvider.Now; }); How would you go about unit-testing such a...

How to stub Python methods without Mock

I'm a C# dev moving into some Python stuff, so I don't know what I'm doing just yet. I've read that you don't really need Dependency Injection with Python. I've been told you can instantiate objects in your code and have them run the way you want, however, you can point methods on those objects to my own stubs defined in my tests - supp...

Spring's MockHttpServlet(Request|Response) alternatives?

In 'spring-test' there's mock classes for unit testing Servlets, which is very useful. Unfortuately, I do not need any of the other Spring componenets, and do not wish to depend on spring-core in my project. It is possible to either: Use spring-test without depending on spring-core, ... (i.e sever the mocking-classes from spring)? Us...

How can I write portlet tests using spring-test package?

I'm trying to test my portlet controllers written using Spring but I don't know how to use org.springframework.mock.web.portlet package. There are lot of examples for org.springframework.mock.web but lack of examples for mocking portlets using Spring. Can anyone show me an example test for portlet controllers? ...

Mock/fake test data generator into NET classes

Does anyone know of a test data generator that will create the code to populate a .NET collection class which can then be copied into a unit test? Searching this site, all the tools mentioned seem to hit databases and I already have Red Gate's SQL Data Generator for that task. However if one follows the TDD paradigm and/or model first d...

How to mock to twitter api using Ruby on Rails?

I'm developing a application that uses the twitter API. I'm currently using rspec with mocha, but I found it to be cumbersome and I cannot reuse the mocking that I create for a give method. Is there a way that you can have for a give call, return something, and for another call return something else? Or it needs to be by each method? ...