mocking

How do you unit-test code that interacts with and instantiates third-party COM objects?

One of the biggest issues currently holding me back from diving full steam into unit testing is that a really large percentage of the code I write is heavily dependent on third-party COM objects from different sources that also tend to interact with each other (I'm writing add-ins for Microsoft Office using several helper libraries if yo...

Best Mocking Library

Which is the best mocking library for C# 3.0/ ASP.NET MVC? Why? ...

Is object mocking used extensively?

I am curious about how many of you folks incorporate mocking of objects (frameworks like JMock, NMock, RhinoMocks hand in hand with unit testing frameworks) into your daily development process. What are your experiences? You see, I develop on top of a GIS (geographic information systems) platform, in which most of work pertains to some ...

Using jmockit expectations with matchers and primitive types

I'm using jmockit for unit testing (with TestNG), and I'm having trouble using the Expectations class to mock out a method that takes a primitive type (boolean) as a parameter, using a matcher. Here's some sample code that illustrates the problem. /******************************************************/ import static org.hamcrest.Match...

Mocking method results

I'm trying to find a way to fake the result of a method called from within another method. I have a "LoadData" method which calls a separate helper to get some data and then it will transform it (I'm interested in testing the transformed result). So I have code like this: public class MyClass(){ public void LoadData(){ SomePrope...

How to mock object construction?

Is there a way to mock object construction using JMock in Java? For example, if I have a method as such: public Object createObject(String objectType) { if(objectType.equals("Integer") { return new Integer(); } else if (objectType.equals("String") { return new String(); } } ...is there a way to mock out...

Unit Testing in .NET: How to Mock Entity Data Provider

Does anyone know whether there's a way to mock Entity Data Provider so Unit Tests don't hit the live data? I found this blog but it seems the project hasn't been released: http://www.chrisdoesdev.com/index.php/archives/62 Thanks ...

What is your favorite Python mocking library?

What is your single favorite mocking library for Python? ...

Rhino mocks ordered reply, throw exception problem

I'm trying to implement some retry logic if there is an exception in my code. I've written the code and now I'm trying to get Rhino Mocks to simulate the scenario. The jist of the code is the following: class Program { static void Main(string[] args) { MockRepository repo = new MockRepository(); ...

Is it feasible to introduce Test Driven Development (TDD) in a mature project?

Say we have realized a value of TDD too late. Project is already matured, good deal of customers started using it. Say automated testing used are mostly functional/system testing and there is a good deal of automated GUI testing. Say we have new feature requests, and new bug reports (!). So good deal of development still goes on. Note...

How can I mock/fake/stub sealed OracleException with no public constructor?

In my tests I need to test what happens when an OracleException is thrown (due to a stored procedure failure). I am trying to setup Rhino Mocks to Expect.Call(....).Throw(new OracleException()); For whatever reason however, OracleException seems to be sealed with no public constructor. What can I do to test this? Edit: Here is exa...

In which cases do you test against an In-Memory Database instead of a Development Database?

When do you test against an In-Memory Database vs. a Development Database? Also, as a related side question, when you do use a Development Database, do you use an Individual Development Database, an Integration Development Database, or both? Also++, for unit testing, when do you use an In-Memory Database over mocking out your Reposito...

How can I write a unit test for a controller class that uses winforms for views?

Has anyone been able to successfully unit test methods that are, by necessity, coupled to the System.Windows.Forms.Form class? I've recently been working on a C# winforms application, trying to build it with an MVC structure. This is difficult enough, given that the framework isn't really built with this in mind. However, it gets even...

Mocking classes that aren't interfaces

I've been writing some providers in c# that inherit from the providerbase class. I've found that it's hard to write tests that use the providers as most mocking frameworks will only allow you to mock an interface. Is there any way to mock a call to a provider that inherits from providerbase? If not, is there a pattern that I can use t...

What are the dangers of making a method virtual?

I've been doing some mocking with RhinoMocks and it requires that mocked methods be made virtual. This is fine except we have a custom framework which contains the methods that I want to mock which are currently not marked as virtual. I can't forsee any problem with making these methods virtual but I was wondering what are some potentia...

When to use partial mocks?

I'm starting to get comfortable with the idea of fakes, stubs, mocks, and dynamic mocks. But I am still a little iffy in my understanding of when to use partial mocks. It would seem that if you're planning on mocking a service and need to resort to a partial mock then it is a sign of bad design. Is it that partial mocks are mostly f...

Which object should I mock?

I am writing a repository. Fetching objects is done through a DAO. Creating and updating objects is done through a Request object, which is given to a RequestHandler object (a la Command pattern). I didn't write the DAO, Request, or RequestHandler, so I can't modify them. I'm trying to write a test for this repository. I have mocked out...

What's the best strategy for unit-testing database-driven applications?

I work with a lot of web applications that are driven by databases of varying complexity on the backend. Typically, there's an ORM layer separate from the business and presentation logic. This makes unit-testing the business logic fairly straightforward; things can be implemented in discrete modules and any data needed for the test can b...

TDD and Mocking out TcpClient

How do people approach mocking out TcpClient (or things like TcpClient)? I have a service that takes in a TcpClient. Should I wrap that in something else more mockable? How should I approach this? ...

How to mock with static methods?

I'm new to mock objects, but I understand that I need to have my classes implement interfaces in order to mock them. The problem I'm having is that in my data access layer, I want to have static methods, but I can't put a static method in an interface. What's the best way around this? Should I just use instance methods (which seems ...