mocking

What is more important, testability of code, or adherence to OOP principles?

My teams evolution of TDD includes what appear to be departures from traditional oop. Moving away from classes that are self sufficient We still encapsulate data where appropriate. But in order to mock any helper classes, we usually create some way to externally set them via constructor or mutator. We don't use private methods, ever. ...

Where do you take mocking - immediate dependencies, or do you grow the boundaries...?

So, I'm reasonably new to both unit testing and mocking in C# and .NET; I'm using xUnit.net and Rhino Mocks respectively. I'm a convert, and I'm focussing on writing behaviour specifications, I guess, instead of being purely TDD. Bah, semantics; I want an automated safety net to work above, essentially. A thought struck me though. I ...

What is your favorite Delphi mocking library?

I want to start using mock objects on my Delphi projects. After a quick google I've found those: Delphi Mock Wizard PascalMock So my question is what one is your favourite and why? ...

How can one mock/stub python module like urllib

I need to test a function that needs to query a page on an external server using urllib.urlopen (it also uses urllib.urlencode). The server could be down, the page could change; I can't rely on it for a test. What is the best way to control what urllib.urlopen returns? ...

Why do I need a mocking framework for my unittests?

Recently there has been quite some hype around all the different mocking frameworks in the .NET world. I still haven't quite grasped what is so great about them. It doesn't seem to be to hard to write the mocking objects I need myself. Especially with the help of Visual Studio I quickly can write a class that implements the interface I w...

Can (or should) I mock methods on the object being tested other than the method being tested?

I have a class like so: public class ClassA { public bool MethodA() { //do something complicated to test requiring a lot of setup } public bool MethodB() { if (MethodA()) //do something else //do something else endif } } I have tests for MethodA and wan...

Unit Testing SiteMapNode

Does anyone know how to unit test SiteMapNode? We’re building some custom navigation controls, which renders unordered html lists from Site Maps with custom attributes. I’m trying to follow a test first approach but am finding that SiteMapNode has internal dependencies on HttpContext. To traverse the site map file it insists on using a ...

Unit testing method that uses UI controls.

I'm currently writing some methods that do some basic operations on form controls eg Textbox, Groupbox, these operations are generic and can be used in any application. I started to write some unit tests and was just wondering should I use the real form controls found in System.Windows.Forms or should I just mock up the sections that I...

Mocking a COM object

I have been working on a wrapper for a COM object that can only take and return strings. The interface for the COM object looks like this: interface IMapinfo { void Do(string cmd); string Eval(string cmd); } Now I have made classes that wrap up basic functions like so: public class Table { ...

How to mock ADO.Net Dataservice calls from Silverlight

Has anyone found a good method of mocking out ADO.Net Data Service calls from a Silverlight application? The power of Data Services seems to be the use of linq, client side, over entities. However when testing the objects that do the data access how can you mock out the service? One way is to create an entire mock Data Service, but th...

How to correctly unit test my DAL?

I'm new to unit testing. But how do I unit test my DAL which is written with Entity Framework, so I can make sure my DAL code is working correctly but no database is actually touched? Could someone give as much detail as possible please. Thanks, Ray. Note: this post is relevant to my other post Mocking vs. Test DB? which is asked aft...

Mocking vs. Test DB?

Earlier I asked this question How to correctly unit test my DAL?, one thing left unanswered for me is if to really test my DAL is to have a Test DB, then what is the role of mocking vs. a testing DB? To add on this, another person suggested to "use transactions and rollback at the end of the unit test, so the db is clean", test db that ...

Why would I write a fake class and unit test it?

I understand the need to test a class that has logic (for instance, one that can calculate discounts), where you can test the actual class. But I just started writing unit tests for a project that will act as a repository (get objects from a database). I find myself writing a 'fake' repository that implements an ISomethingRepository in...

Mocking for Dummies?

I'm new to mocking, I have a new .net web project that is in UI->BLL->DAL->DB structure, I use NUnit to do some testing currently. I intent to use it to test middle tier so I don't have to actually write to DB. Now, I've never done any mocking, don't quite know where to start, so I am looking for a mocking framework that has some end to...

Mocking attributes - C#

I use custom Attributes in a project and I would like to integrate them in my unit-tests. Now I use Rhino Mocks to create my mocks but I don't see a way to add my attributes (and there parameters) to them. Did I miss something, or is it not possible? Other mocking framework? Or do I have to create dummy implementations with my attribut...

Passing web context to a 'service' in ASP MVC app

Hi I'm trying to work out a way of passing the web current http context to a service class (or initialising the class with a reference to it). I am doing this to abstract the rest of the app away from needing to know anything about the http context. I also want the service to be testable using TDD, probably using one of the Mockable f...

How to MOQ an Indexed property

I am attempting to mock a call to an indexed property. I.e. I would like to moq the following: object result = myDictionaryCollection["SomeKeyValue"]; and also the setter value myDictionaryCollection["SomeKeyValue"] = myNewValue; I am doing this because I need to mock the functionality of a class my app uses. Does anyone know how...

Rhino Mocks - Setting up results for non-virtual methods

I'm playing around with Rhino Mocks and am trying to set some dummy results on my mocked objects so when they are called in my factory methods I don't have to worry about the data. But I've hit a snag, the methods I want to have the dummy results for are causing exceptions because they aren't virtual. I've got code like this: using(mo...

Mock Objects in PHPUnit to emulate Static Method Calls?

I am trying to test a class that manages data access in the database (you know, CRUD, essentially). The DB library we're using happens to have an API wherein you first get the table object by a static call: function getFoo($id) { $MyTableRepresentation = DB_DataObject::factory("mytable"); $MyTableRepresentation->get($id); ... do s...

Using Moq to determine if a method is called

Im very new top mocking frameworks, but I have decided to take a look at Moq. It is my understanding that I can test that a method call will occur if I call a higher level method i.e. public abstract class SomeClass() { public void SomeMehod() { SomeOtherMethod(); } internal abstract void SomeOtherMethod(...