unit-testing

NUnit executes with alternate constructor

I have a class which has some unit tests, but when I am running tests I would like the class to be created with a different constructor. Something like this: [TestFixture] public class MyClass { public MyClass() { /* set up for production */ } [TestFixtureConstructor] public MyClass() { /* set up for testing */ } [Test...

Unit testing Couchdb model in Pylons

Given a default pylons installation are there any examples available on the best practices for unit testing a CouchDB model? ...

Testing a card deck shuffler

I have a class PlayingCard which represents a particular playing card. I have another class, Deck, which contains a list of PlayingCard objects. Deck has a shuffle() method that randomizes the card order. I would like to write some unit tests for the shuffle() method, but I'm at a bit of a loss. I'd prefer the test to not care about ...

How to get real code coverage using vsinstr/vsperfmon

Hi, my microsoft-based development environment looks like this: - huge native c++ codebase, seperated into 10 projects - each project has a dependent test project (GoogleTest unit tests), the sources to test are simply referenced. I generated the coverage-report using vsinstr and vsperfmon (the visual studio tools for instrumenting/...

xUnit.net Test Stripper [to remove test code embedded in binaries prior to deployment/shipping]

Is there a Test Stripper (as defined in xUnit Test Patterns) available that supports removing classes containing methods tagged as [Fact]s etc. plus the dependency on xunit.dll from binaries [as part of a build process] ? Further details of the full requirements and context are at this xUnit CodePlex post. Failing that (something that ...

GWT Mockito integration

I'm trying to set up and use Mockito into a GWT project, and I'm having trouble using it on the client side (in javascript). I tried to add a module and include Mockito, but it seems not to work (lots of errors). I also tried to do a full checkout from svn and integrate GWT in it that way, the same errors. How should this be done? Thanks...

Unmanaged C++ Unit testing in Visual Studio 2008

I want to create a managed C++ unit test project to test an unmanaged MFC project. I have read msujaws's procedural and followed it. I implemented a test method to test the return string of a function like so: #include "stdafx.h" #include "TxStats.h" #include <cstdlib> #include <atlstr.h> #pragma managed #using <mscorlib.dll> #using <...

What do you do to test methods that produce complicated object graphs?

I'm a controls developer and a relative newbie to unit testing. Almost daily, I fight the attitude that you cannot test controls because of the UI interaction. I'm producing a demonstration control to show that it's possible to dramatically reduce manual testing if the control is designed to be testable. Currently I've got 50% logic c...

Why is it a best practice to always unit test the smallest possible unit of code? I find those tests will never survive a refactoring.

I've been a practitioner of test driven development for several years, and overall i'm happy with it. The one part that I don't yet understand is the idea that you should always be unit testing the 'smallest possible unit'. Part of the idea of unit testing seems to be to allow you to refactor with confidence that you won't break anythi...

moq - how to verify method has not been called if the class swallows exceptions

I am trying to test a fairly complex class using Moq and am running into a problem. I am trying to verify that a method does NOT get called, and usually this is simple to do by setting MockBehavior.Strict, but here however the class has its own error reporting mechanism so it swallows the exception being thrown by Moq. .VerifyAll metho...

Philisophical Questions about Test-Driven Development

I have been perpetually intrigued by test-driven development, but I can never follow through with it when I try it on real projects. I have a couple of philosophical questions that continually arise when I try it: How do you handle large changes? When it comes to testing single functions (some parameters, a result value, few side eff...

is testing the public API enough for unit testing an API component?

Hi, My software (application) exposes an API (webservices) using httplistener. Is it from a unit test point of view enough to test the API functions through web requests? I ask this since I read that a best practice is to test only the public methods of a class. In this case I'm not testing public methods of a class but the public API ...

What's the most commonly used unit testing framework for different types of Ruby applications?

Are the same unit testing frameworks used for different web frameworks - Rails, Merb, Sinatra, Ramaze and desktop frameworks - Shoes? And what is the most widely used unit testing framework that would work with all of the various web and desktop frameworks? ...

What's the main difference between cucumber and shoulda?

How would you make a decision between cucumber and shoulda if you were about to choose a testing framework? What differentiates these two frameworks primarily? ...

Unit Testing - how much more time does it really add?

I have heard that writing (coding) unit tests for your application effectively doubles the development time required for projects. Is this true, particularly for beginners? Also some follow-up questions (brownie points): If you were doing a client project that you hand off when finished, is it worth the time and effort to do unit testin...

TDD in a text file import project

I'm just starting, and yes, i haven't written any tests yet (I'm not a fundamentalist, I don't like compile errors just because there is no test), but I'm wondering where to get started on doing a project that parses fixed length flat file records according to an XML mapping, into a class that represents the superset of all file layouts,...

How to trigger Initialize method while trying to Unit Test?

I have the override below to do a few things with cookies using the FormsIdentity Object. But when I instantiate a controller on my Unit Testing this method is not triggered. Any ideas how to do this? protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); ...

Mocking virtual readonly properties with moq.

I couldn't find a way to do this, though this can be done by hand so why not with moq? ...

Can I make NUnit execute tests in random order?

Greetings, I would like to make NUnit execute my unit tests in a random order every time in order to ensure they are isolated and FIRST. Does anyone know of a easy way to do this well without branching NUnit? ...

Data access, unit testing, dependency injection

Hello all, I've recently got a task to create a simple utility that allows to import data from a file with special format to the database. I've implemented console application with few classes(Program class operates with business logic class, business logic class in turn operates with data access class). Everything works ok, but now I'm...