mocking

Are there any automocking libraries in the Java world?

I'm looking for something similar to the structuremap or eleution automocking containers in the .NET world ...

Mocking framework from Microsoft?

I want to start using mock objects on my c# project. After a quick google I've found that most folks use one of the below: NMock EasyMock.Net TypeMock Isolator Rhino Mocks Moq Does Microsoft provide a similar framework for mocking? I'm using Visual Studio tests for my unit test now. ...

Why doesn't Moq run the overridden ToString method?

In the following code why does mockTest.ToString() return Null? EDIT: Added comment into example code to show how to fix the problem. Public Sub Main() Try Dim test = New TestClass If test.ToString <> "stackoverflow rules" Then Throw New Exception("Real Failed: Actual value: <" + test.ToString + ">") ...

PHPUnit: stub methods undefined

I must be missing something. I'm trying to stub methods on a class in PHPUnit, but when I invoke the method on the mock object, it tells me that method is undefined. Example class to stub: namespace MyApp; class MyStubClass { public function mrMethod() { // doing stuff } } To stub it, I write: // specifying all ge...

How to mock users and requests in django

I have django code that interacts with request objects or user objects. For instance something like: foo_model_instance = models.get_or_create_foo_from_user(request.user) If you were going to test with the django python shell or in a unittest, what would you pass in there? Here simply a User object will do, but the need for a mock req...

How do I mock/fake: Many to many objects

Hello, So in my domain I have 3 objects. User, Item and Tag. Each user has items and tags, each item has tags and each tag has items. The objects look a little like this: public class User { public List<Item> Items { get; set; } public List<Tag> Tags { get; set; } } public class Item { public List<Tag> Tags { get; set; } ...

RhinoMocks - Fetching parameters of called functions

Using RhinoMocks - can I fetch the parameters of a called function? I mean; can I get some of the unknown parameters from the function call out? I have a mock, and I expect some function to be called on this. I know one of the parameters, but the other one is unknown as this comes from the class that uses the mock and calls a function ...

TDD - top level function has too many mocks. Should I even bother testing it?

Hello, I have a .NET application with a web front-end, WCF windows service back-end. The application is fairly simple - it takes some user input, sending it to the service. The service does this - takes the input (excel spreadsheet), extracts the data items, checks SQL db to make sure the items are not already existing - if they do not ...

How to mock System.DirectoryServices.SearchResult?

If you have a method that needs to be tested that takes a list of SearchResults public virtual void ProcessResults(IList<SearchResult> list) { //Code to tests here } How do you mock up that list of SearchResult? Note: No low-level injection frameworks (eg TypeMock) allowed. ...

Mocking 3rd party callback events using moq

We've been trying write unit tests for a worker class written in C#, which mocks out a third party API (COM based) using moq to dynamically create the mock objects. NUnit is our unit testing framework. This third party component implements a couple of interfaces, but also needs to call back into our worker class using events. Our plan w...

Problems getting a mocking demo working (Nunit and ReSharper)

Hi, I am trying to get to grips with mocking and ReSharper by watching this demo http://www.bestechvideos.com/2008/06/08/dimecasts-net-introduction-to-mocking-with-moq I'm sure I followed the code correctly but I'm getting errors. Could you give me some pointers as to were I'm going wrong? errors:-class name is not valid at this point e...

How can I mock Server.HtmlEncode

I am trying the following, but I am getting : Object reference not set to an instance of an object. HttpContextBase mockContext = MockRepository.GenerateMock<HttpContextBase>(); mockContext.Expect(c => c.Server.HtmlEncode("")).IgnoreArguments().Return(""); mockContext.Expect(c => c.Server.HtmlDecode("")).Return(""); controller.Con...

RhinoMocks - Specifying return for functions called later

Using RhinoMocks - how can I say "whenever some function is called from now on - it should return some value". I'd like to say something like this: fakeCalculator.WhenCalled(factory => factory.AddNumbers(1, 2)).Return(3); And then - when the AddNumbers function is called with 1 and 2 - it will return 3. I.e. I want to define this ...

What are mock objects in Java?

I like to know what mock objects are in Java. Why do we create them and what are their uses? ...

Creating a mock web service from a WSDL file in Python

Hi, We are writing a client for a remote service that exposes SOAP web services and publishes a WSDL definition for those services. We don't have access to the system during testing, so we'd like to write a mock service. We're using Python for the client, so ideally we'd want to use Python for the mock server, although I suppose it's ...

rhino mocks mocking a call

Hi all, I have a method that I want to test which hits the database. From what I have read this is a perfect oppurtunity to use a mock. However the problem that I am facing is that I pass the object a string and then it creates an object and hits the db with this object i.e. public void test(string t) { Test t1 = new Test(t); d...

Fitnesse- Should tests talk to the database?

We are trying to use Fitnesse for our Functional test. Should i be mocking dependencies or should it be testing against the database? What are the Pros/Cons of either of the approach? The whole issue of testing against the DB is setting up data which is huge dependency. If we mock then is it real functional test? Thanks ...

Is it possible to mock a Java protocol buffer message?

Protocol buffer classes are marked final, presumably for efficiency; however, this makes them quite difficult to test with -- Mockito can't mock/spy on final classes. I've tried using PowerMockito with no success: I get a ClassFormatError when preparing the final class for the test. My solution up until now is to create mockable adapter...

Mock object returning a list of mocks with Moq

I am trying to test the following code public void CleanUp() { List<ITask> tasks = _cleanupTaskFactory.GetTasks(); //Make sure each task has the task.Execute() method called on them } In my test I create a mocked implementation of _cleanupTaskFactory, and I want to stub the GetTasks() method to return a ty...

BDD/TDD mocking data the tricky way.

So a coworker and I are in a fairly heated debate. We are beginning a new project and we are attempting to use BDD. We are both first-timers and don't fully understand what practices should be used. We've written some specs and we are now implementing the code. Things are getting pretty tricky since there is a lot of database interaction...