mocking

Behavior vs. State Based Testing

I know this question is part of a bit of a religious war, but I have the following situation: I have an object, Responder that calls a method on object Updaterin response to different events. I recently separated the testing in this way: state-based tests for the Updater method itself, and behavior-based tests for the Responder that cal...

Mock File class and NullPointerException

Hi. I'm creating a File mock object with Mockito that will be used as the directory to store a new File. Folder folder = Mockito.mock(File.class); File file = new Agent().createNewFile(folder, "fileName"); and inside my Agent class: public File createNewFile(File folder, String filename){ return new File(folder, "testfile"); ...

Construtor/Setter Injection using IoC in HttpHandler, is it possible??

Hi. I've ran into a rather hairy problem. There is probably a simple solution to this but I can't find it! I have a custom HttpHandler that I want to process a request, log certain info then enter the details in the database. I'm using NUnit and Castle Windsor. So I have two interfaces; one for logging the other for data entry, which a...

Rhino Mocking and TDD with legacy code

Hi, First of all let me say I am working from legacy code. So some changes can be made but not drastic ones. My problem is I have a "Vehicle" object, it is pretty simple but has no interfaces or anything on it. This project was created before TDD really started to become more main stream. Anyway, I need to add a new method to change th...

Mocking without injection

Hello all, (C#, WCF Service, Rhino Mocks, MbUNit) I have been writing tests for code already in place (yes I know its the wrong way around but that's how its worked out on my current contract). I've done quite a bit of re-factoring to support mocking - injecting dependencies, adding additional interfaces etc - all of which have improve...

RhinoMock : Mocks Vs StrictMocks Vs DynamicMocks

I understand the difference between a Mock and a Stub. But different types of Mocks in RhinoMock framework confuses me. Could someone explain the concepts of Mocks Vs StrictMocks Vs DynamicMocks in terms of RhinoMock framework. your answers are greatly appreciated. ...

Including exception details when using a Castle WCF Facility hosted service

I'm having some trouble unit testing a bit of code while utilising the Wcf Facility for Castle Windsor. It seems to refuse to include Exception Details when an Exception is thrown, I only get to see empty FaultExceptions. This is my test setup: First, here's a stub of the service that I will be connecting to: [ServiceBehavior(IncludeEx...

How can I inject an object into another namespace in python?

I'm writing some unittests for code written by someone else here at the office. Python is not my strongest language. While I've been successful with basic unit tests, mocking in python is throwing me for a loop. What I need to do is override a call to ConfigObj and inject my own mock config/fixture into any ConfigObj call. settings.py ...

How do I stub out the flickraw library in my app's unit tests?

My Rails 2 app displays a slideshow of photos from Flickr via the flickraw library. My code works, but I'm stuck on how to properly write RSpec unit tests. I have a Slide class that encapsulates everything that my app needs from flickraw. It acts somewhat like a model object but doesn't use ActiveRecord. It doesn't do much work; it de...

Mocking, Unit Testing (NUnit) setup problem with HttpHandler

This post relates to two other posts, here and here. I'm new to Unit Testing & Mocking. I have a test fixture that is trying to mock a HttpContext object including the response and request. I think the test code is not setup properly, as after calling the handler I get an error immediately. There error I am getting is: UnitTests.UADHan...

What are the predominant .NET 3.0 mocking frameworks?

To preface this, I love Moq. I wish I could use it in .NET 3.0. Sadly, however, I cannot, but I would still like to use mocks for unit testing purposes. Also, I've used Rhino before, but I absolutely hate it. To be a little more descriptive, though, it's because the interface feels clunky and unintuitive--which can be dealt with--and the...

Function Programming and Mock Objects

Hi I was recently watching a webcast on Clojure. In it the presenter made a comment in the context of discussing the FP nature of Clojure which went something like (I hope I don't misrepresent him) "Mock objects are mocking you". I also heard a similar comment a while back when I watched a webcast when Microsoft's Reactive Framework w...

Using soapUI API to create a soapUI Mock object

I try to create a soap UI WSDL Mock Service using the soapUI API. But there seems to be no documentation of the source code. Has anyone done this before or something in that direction? ...

What is the most complete mocking framework for HttpContext

I'm looking for as comprehensive as possible of a mock replacement and wrapper for the ASP.NET HttpContext in my applications. A comprehensive mock replacement could potentially increase the testability of my ASP.NET web applications substantially, without necessitating migrating every application to more-testable frameworks such as MVC....

How do mocking frameworks (in .Net) create mock objects?

In the context of the Microsoft .Net Framework, I'm really curious about how mocking frameworks (Rhino Mocks, Moq, NMock, etc.) actually create the mock objects from a given type. I'm interested in either the specific mechanics of one method or, if they use different methods perhaps some overview of the different ways. Alternatively, i...

looking for a C# mocking framework that allows mocking static methods

i am required to quickly learn a mocking framework that allows mocking static methods and write test cases for an application written in C#. which framework would you recommend? ...

Am I doing something fundamentally wrong in my unit tests?

After reading an interesting article about unit testing behavior instead of state, I came to realize that my unit tests often are tightly coupled to my code because I am using mocks. I cannot image writing unit tests without mocks but the fact is that these mocks are coupling my unit test very much to my code because of the expect andRet...

Rspec: How to test recursion?

I'd like to test that a method is called recursively with a specific argument. My approach: class Recursable def rec(arg) rec(7) unless arg == 7 end end describe Recursable do it "should recurse" do r = Recursable.new('test') r.should_receive(:rec).with(0).ordered r.should_receive(:rec).with(7).ordered r.rec(...

What is the purpose of mock objects?

I am new to unit testing, and I continously hear the words 'mock objects' thrown around a lot. In layman's terms, can someone explain what mock objects are, and what they are typically used for when writing unit tests? ...

How can a class be designed to mock an unknown type?

I've seen examples of this where an interface is provided to a factory and it generates objects that implement the interface. This isn't that complicated to me, but what I don't get is how that can be used to implement behavior. Take for example the ChannelFactory in WCF... when you generate a channel from an interface it exposes met...