mocking

Easymock: does the order of captures matter?

This might seem like a pretty detailed question about Easymock, but I'm having a hard time finding a support site/forum/mailing list for this library. I'm encountering a bug when using the captures() method that seems to return the captured parameters out of order. Here's a simplified version of what I am testing: public class Capture...

How do I mock a private field?

I'm really new to mocks and am trying to replace a private field with a mock object. Currently the instance of the private field is created in the constructor. My code looks like... public class Cache { private ISnapshot _lastest_snapshot; public ISnapshot LatestSnapshot { get { return this._lastest_snapshot; } ...

Returning mock objects from factory girl

I am using Mocha and Factory_girl in a JRuby rails application. When I call the factory I would like to return the objects with some mocking already done. Here is a code snippet of what I am trying to do. Factory.define :tweet_feed_with_tweets, :parent => :tweet_feed do |t| t.expects(:pull_tweets).returns([Factory.build(:status),Fac...

How to mock the property which returns the list object - In rhino mock

Interface IView { List<string> Names {get; set;} } public class Presenter { public List<string> GetNames(IView view) { return view.Names; } } var mockView = MockRepository.GenerateMock<IView>(); var presenter = new Presenter(); var names = new List<string> {"Test", "Test1"}; mockView.Expect(v => v.Names).Return(name...

How can I avoid large multi-step unit tests?

I'm trying to unit test a method that performs a fairly complex operation, but I've been able to break that operation down into a number of steps on mockable interfaces like so: public class Foo { public Foo(IDependency1 dp1, IDependency2 dp2, IDependency3 dp3, IDependency4 dp4) { ... } public IEnumerable<int>...

Creating mock data for unit testing

I consider myself still pretty new to the TDD scene. But find that no matter which method I use (mock framework or stubbing my own objects) I find that I have to write a lot of code to create mock data. I like the idea of loading up objects to create an in-memory database. But what I don't like is cluttering up my tests with a ton of cod...

Can I use map coercion in groovy to mock a class with a constructor that has parameters?

Java example classes under test public class Sample { public void printPie() { System.out.println("Pie."); } } public class SampleCont { String _PIE; public SampleCont() { _PIE = "pie"; } public void printPie() { System.out.println(_PIE); } } public class SampleContArg { String...

Mocking an Entity Framework model?

Is it possible to mock an EF model so that I can test code which uses the model classes without getting rid of LINQ to Entities code strewn throughout my project? Or will it be necessary to set up a test database for the model to hit instead? ...

Mock abstract class default behaviour with Rhino

I'm pretty new to mocking so this might be something I'm just not picking up on yet, but I can't find a good example anywhere. I'm trying to assert that by default, any class that inherits from my abstract class will instantiate a collection in the constructor. Here's the abstract class: public abstract class DataCollectionWorkflow : ...

Is there anything like RhinoMocks in Java?

What would be the closest resemblance? ...

Can I mock a super class method call?

Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymock or jmock (and I think it is not possible). There is a (relative) clean solution, to create a delegate with the super class method logic and then set expectati...

Do Visual Studio 2005 testing tools contain tools for mocking?

I'm working with VSTS 2005, and while the unit testing tools are fairly straightforward, I'm left wondering if there is any sort of support for mocking. I'd hate to have to do the mocking manually, because that leads to a lot of (mostly generated) boilerplate code. I have an edict from The Powers That Be, that a third-party mocking libr...

Using Rhino Mocks how can I set a property of a parameter for a Mocked method

Using the new Rhino Mocks 3.5 Arrange/Act/Assert (AAA) Testing style, I'm having problems writing a test. I have a method that calls a method on a repository class. ActivateFoo, where my Foo object has an IsActive property. The result of the ActivateFoo object should change the property. Here is sample code: [TestMethod] public void ...

Mocking the CAL EventAggregator with Moq

Hi, I'm using the Composite Application Library's event aggregator, and would like to create a mock for the IEventAggregator interface, for use in my unit test. I'm planning on using Moq for this task, and an example test so far looks something like this: var mockEventAggregator = new Mock<IEventAggregator>(); var mockImportantEvent =...

What should I consider when choosing a mocking framework for .Net

There are lots of mocking frameworks out there for .Net some of them have been superseded by others that are better in everyway. However that still leaves many mocking frameworks that have different styles of usage. The time it takes to learn all of them well enough to decide witch to use is unreasonable. I don’t believe that we have ...

How to avoid duplicate logic with Mocks

I have the following challenge, and I haven't found a good answer. I am using a Mocking framework (JMock in this case) to allow unit tests to be isolated from database code. I'm mocking the access to the classes that involve the database logic, and seperately testing the database classes using DBUnit. The problem I'm having is that I'm ...

Mocking using 'traditional' Record/Replay vs Moq model

I'm new to mocks and am deciding on a mock framework. The Moq home quotes Currently, it's the only mocking library that goes against the generalized and somewhat unintuitive (especially for novices) Record/Reply approach from all other frameworks. Can anyone explain simply what the Record/Replay approach is and how Moq diff...

How do you Mock IUnityContainer?

I'm trying to Mock the IUnityContainer using Moq 3.0 I'm getting a BadImageFormatException, but not when debugging. From the looks of it I'm not the only one that's ran into this problem. here And its a registered issue for Moq here I'm just curious if anyone has found a solution... closest I've found is a nice solution that uses Rh...

Needed: File system interfaces and implementation in .NET

I write unit tests to my code, using Moq as a mocking framework. My code includes calls to the file system, using direct calls to System.IO classes. For instance, File.Exists(...) etc. I'd like to change that code to be more testable, so I should have an interface, say IFile, with a relevant method, say Exists(string path). I know I can ...

Mocking a Urllib2.urlopen that raises an HTTPError 404 using pymox

I am try to mock out an urllib2.urlopen that will raise a HTTPError 404. This is what I have so far: import urllib2 import mox # check that it works req = urllib2.Request('http://www.google.com/') print urllib2.urlopen(req) # OK, let's mock it up m = mox.Mox() m.StubOutWithMock(urllib2, 'urlopen') # We can be verbose if we want to :) ...