stubbing

Automatic stubbing in java word. What to use?

Hi, I have huge class that I need to build stub for. To give you picture it is Messages class of the GWT. Often this is class with dozens of methods that return String. With JMock I can do stubbing, but I will end with allowing each method... This is not something that I would like to see. Is there something that will automatically b...

Groovy: stub typed reference

Hi, I have a Groovy class similar to class MyClass { Foo foo } Under certain circumstances I don't want to initialize foo and want to stub out all the calls to it. Any methods that return a value should do nothing. I could do it like this: Foo.metaClass.method1 = {param -> } Foo.metaClass.method2 = { -> } Foo.metaClass.method3 = ...

How can I stub or mock the request.subdomains method in Rails?

I am trying to write some functional tests in my rails app, and in the application_controller.rb I have this: before_filter :current_account def current_account @current_account ||= Account.find_by_subdomain!(request.subdomians.first) end When running tests, request.subdomains doesn't contain the valid subdomains I'm looking for and...

Unit Testing Adding to Zip / Extracting from Zip

I have the following code for adding to/extracting from Zip. I'm trying to refactor this to make it test-ready. Can someone provide pointers on how I can accomplish this? Aside: I'm using Moq as my mock framework and MSTest as my Unit Testing tool private const long BufferSize = 4096; public static void ExtractZip(string zipFilename...

unit testing datastores in PHP

I'm using PHPUnit but find it difficult to make it create good mocks and stubs for objects used as datastore. Example: class urlDisplayer { private $storage; public function __construct(IUrlStorage $storage) { $this->storage = $storage; } public function displayUrl($name) {} public function displayLatestUrls($count) {} ...

When to use stubs and mocks?

I've this confusion all the time. If I write a code which uses fake code to assert some operation, how do i trust my real implementation when it is started really using the real objects instead of fake ones. For example, I've this code -- [Test] public void CanCreateContactsWithData() { using(ISession session = fact...

RhinoMocks exceptions when stubbing out Equals method

Hi! I've a problem setting up a test for an Equals method on an object. The object in question is defined by this interface: public interface IHours { ITimeOfDay OpenAt { get; set; } ITimeOfDay CloseAt { get; set; } DateTime ValidFrom { get; set; } DateTime ValidTo { get; set; } bool isCovered(DateTime time); } a...

RhinoMocks - Stub a Method That Returns a Parameter

I am using RhinoMocks, I need to stub a method, and always have it return the third parameter, regardless of what is passed in: _service.Stub(x => x.Method(parm1, parm2, parm3)).Return(parm3); Obviously, it ain't that easy. I don't always know what the parms are going to be, but I know I always want to return the 3rd one. ...

How can I stub the Properties.Settings object when the unit test is in a different assembly?

I have an object the references a bunch of Properties.Settings.Default... values and I need to stub these in the unit test for this object. Unfortunately the type for the settings object is declared as internal and so I can't access it from the unit test project. How can I stub up the return values for these properties? I'm using Rhino...

Given wsdl + xds type file, how do I create a stub WCF webservice?

I understand this is a basic topic but never done this before starting from wsdl. I am being handed a wsdl file and a bunch of xsd with the types definitions. I don't have a clue if they were created from a WCF service (I guess so because of the split out format) but I do need to create a WCF service that implements the contract. Quest...

How can I stub a before_filter in a super class in Rails?

I'm using RR for mocking and stubbing in RSpec, and I've run across a situation where I'd like to stub a method from a super class of a controller that sets some instance variables. I can work out how to stub the method call and if I debug I can see that my stubbed block is called, but I cannot get the instance variables in the block to ...

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

Hi, I have a method i'd like to stub but it has a lot of parameters. How can i avoid mocking all parameters but still stub the method. Ex: //Method to stub public void myMethod(Bar bar, Foo foo, FooBar fooBar, BarFoo barFoo, .....endless list of parameters..); ...

mocha and nested objects

Excuse if this is a silly question, I am new to mocking. I am able to use mocha to do things like: person.expects(:first_name).returns('David') How can I mock a nested object? Say I have a Product that belongs to a Person and I want to get the first name of that person. In my app I might do it like this: product.person.first_name ...

Rhino Mocks stubs and mocks are only good for interfaces?

Is it correct that Rhino Mocks stubs and mocks are only good for interfaces, not concrete classes? I spent quite a time trying to make this piece of code working. What I did not expected is that stabbed pubSubClient will always call Send method from the class. That method has some dependencies and throws exception. [Test] public void Te...

Stubbing ActiveRecord result arrays

Using Ruby 1.8.6, stubbing a finder method to return an Array does not work when the code under test calls the 'count' method on the result: User.any_instance.stubs(:friends).returns([user1, user2]) That's because Array.count has only been added in Ruby 1.8.7. Rails also adds a count method dynamically, I believe through the ActiveRec...

Difference in techniques for setting a stubbed method's return value with Rhino Mocks

What is the main difference between these following two ways to give a method some fake implementation? I was using the second way fine in one test but in another test the behaviour can not be achieved unless I go with the first way. so (the first), using (test.Record()) //test is MockRepository instance { service.GetUser("dummyName"...

RSpec on Controller and Stubbing

I am pretty new to using rspec and am trying to write my tests for my controllers. I have this controller (I am using mocha for stubbing): class CardsController < ApplicationController before_filter :require_user def show @cardset = current_user.cardsets.find_by_id(params[:cardset_id]) if @cardset.nil? flash[:notice]...

Expectation for find not working, but expectation for find_by_id is

I have this controller code: # GET /cardsets/1 def show @cardset = current_user.cardsets.find_by_id(params[:id]) end And this RSpec test code (mocking with Mocha): # GET Show context "on get to show" do it "should assign cardset" do @cardset = Factory(:cardset) @profile = @cardset.profile @profile.cardsets.expects(:f...

Where/what to test? Mocks, stubs, functional, unit... (in Ruby/Rails)?

Hi all, I'm trying to test a fairly large Rails app, which I probably should have been doing all along but never felt entirely comfortable with. Now I'm working on a functional test to see if a user is created successfully. Basically, I'd like to test a few things: whether the user was saved (i.e., if there's a new record in the DB) ...

VS2005 Options Generate Method Stub not working.

Ok I installed the linq preview(May 2006) and it seems to have screwed me up. Now the one the of the most important features in VS2005 is not working anymore (Options Generate Method Stub (Shift+Alt+F10)). I used to get this message every time I would start a project ("This is an unsupported version of Microsoft Visual C# 3.0 / Microsoft...