unit-testing

How to go about mocking a class with final methods?

Say I have class A with class A { final String foo() { // .. computing result, contacting database, whatever .. return "some computed value"; } // ... and a bazillion other methods, some of them final. } Now I have class B with class B { String methodIWantToTest(A a) { String output = a.foo(); // ... whate...

What is the best way to store static unit test variables?

I am currently using NUnit and testing a class library. Up until now, I have used a list of constants at the top of the test class to hold some static test variables. Is this the best way to do this, or is there a more fluent way to handle it? ...

Preferred Python unit-testing framework

Hello, So far I've been using the built-in unittest module for unit-testing Python code. However, for simple cases it seems like an overkill. Being a derivative of xUnit, it appears a bit heavy for the dynamic nature of Python, where I would expect to write less to achieve the same effects. On the other hand, it is built-in, makes you w...

How to force a MSTEST TestMethod to reset all singletons/statics before running?

I'm using MSTEST inside Visual Studio 2008. How can I have each unit test method in a certain test class act as if it were the first test to run so that all global state is reset before running each test? I do not want to explicitly clean up the world using TestInitialize, ClassInitialize, AssemblyInitialize, etc. For example: [TestClas...

How to make Visual Studio Pause after executing a console app in debug mode?

I have a collection of boost unit tests I want to run as a console application. When I'm working on the project and I run the tests I would like to be able to debug the tests and I would like to have the console stay open after the tests run. I see that if I run in release mode the console window stays up after the program exits, but i...

How do you organize unit tests into packages?

As a matter of fact you have smth like /java/src and /java/test. But then, how do you name packages/classes the unittests go to? The same as classes they are written against? And when refactoring comes, do you manually rename in /test? Please share your experience. ...

Is it better to hire a developer to do unit tests, or to have each developer do their own?

For a team of 10, is it better to hire an individual developer to do all unit tests, or to have each individual developer do unit tests for their own owned code? ...

What is the code-coverage percentage on your project?

What is the % code-coverage on your project? I'm curious as to reasons why. Is the dev team happy with it? If not, what stands in the way from increasing it? Stuart Halloway is one whose projects aim for 100% (or else the build breaks!). Is anyone at that level? We are at a painful 25% but aspire to 80-90% for new code. We have leg...

Quick Rhinomocks Help

Can someone take a look at this code and tell me if there's any obvious reason it shouldn't be working? When service.getResponse is called within my code the mocking framework only returns null, not the object I specified. [Test] public void Get_All_Milestones() { var mockRepo = new MockRepository(); var serv...

Unit testing a module that checks internet connectivity

I have a C# module responsible for acquiring the list of network adapters that are "connected to the internet" on a windows Vista machine. The module uses the "Network List Manager API" (or NLM API) to iterate over all network connections and returns all those for which the IsConnectedToInternet value is true. I received some suggestion...

How do you mock classes that use RAII in c++

Here's my issue, I'd like to mock a class that creates a thread at initialization and closes it at destruction. There's no reason for my mock class to actually create and close threads. But, to mock a class, I have inherit from it. When I create a new instance of my mock class, the base classes constructor is called, creating the thre...

Hidden folder copied during unit test run on VS2008

I've found that when running a VS2008 unit test that a hidden .svn subversion folder is copied under the Out folder that the unit test creates. This is because I've labeled a Resources folder in my unit test as "Additional File and Folder to deploy." Anybody know if you can mark a folder (in this case the .svn folder) as an exclude? ...

Creating test run configurations in VS 2008

I am working with an n-tiered architecture in Visual Studio 2008 (Developer Edition), and I have run into an issue. We are running unit tests on every method of our services layer, and I am attempting to see the code coverage results, to ensure I'm hitting all the main paths through my methods. When I attempt to view the results, I am ...

Are brittle unit tests always a bad thing?

At times I find a very brittle test to be a good thing because when I change the intent of the code under test I want to make sure my unit test breaks so that I'm forced to refactor ... is this approach not recommended when building a large suite of regression tests? ...

Microsoft Unit Testing failure, unable to load DLL to test

I've got a .NET 3.5 class lib that I am trying to write some automated tests for but I'm getting the following error when running any tests in the solution: Test method Common.Tests.CommonTests.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Library.Common, Version=0.0.1.22004, Culture=...

Is unit testing appropriate for short programs

I'm not a newbie since I've been programming on and off since 1983, but I only have real experience with scripting languages like Applescript, ARexx, HyperTalk and Bash. I write scripts to automate data entry, batch process images and convert file formats. I dabble at Processing, Ruby and Python. Most of the programs I write are under ...

Unit Test the Routes

Let's say I have defined a route: routes.Add(new Route("Users/{id}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller ="UserInfo", action = "UserInformation", id = ""}), }); So, how am I going to create a unit test to ensure that when Users/12...

What tools exist for testing multithreaded .net code?

Are there any tools that can help find race conditions when testing multi-threaded .net code? I'm looking for something with similar capabilities to IBM's ConTest tool for Java. ...

How to pass querystring to testAction in CakePHP 1.2?

In CakePHP putting a querystring in the url doesn't cause it to be automatically parsed and split like it normally is when the controller is directly invoked. For example: $this->testAction('/testing/post?company=utCompany', array('return' => 'vars')) ; will result in: [url] => /testing/post?company=utCompany While invoking the u...

Good resources about unit testing?

Is there any good book or material which covers C# unit testing using mocks in depth? ...