unit-testing

Questions when moving from MbUnit to MsTest

Our team is looking to switch from using mbunit to mstest, but there appears to be some disconnect between the two. Does anyone know how to simulate the CombinatorialTest and Factory attributes from mbunit when using mstest? I think that is our only stumbling block before doing the switch. ...

Unit testing the app.config file with NUnit

When you guys are unit testing an application that relies on values from an app.config file? How do you test that those values are read in correctly and how your program reacts to incorrect values entered into a config file? It would be ridiculous to have to modify the config file for the NUnit app, but I can't read in the values from ...

How do you specify that an exception should be expected using Boost.Test?

I have a Boost unit test case which causes the object under test to throw an exception (that's the test, to cause an exception). How do I specify in the test to expect that particular exception. I can specify that the test should have a certain number of failures by using BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES but that seems rather unsp...

How do you structure your NUnit tests on a large project?

I am interested in seeing if I can improve the way we use NUnit in a Visual Studio solution containing 30+ projects. First, would you have one assembly of tests for every assembly in the solution, or would you try to keep the number of test assemblies down? I started off creating many test assemblies, but I think this is costing us a lo...

What is the equivalent to JUnit in C#?

I am coming from Java and am currently working on a C# project. What is the recommended way to go about a) unit testing existing C# code and b) accomplishing TDD for C# development? Also is there an equivalent to EMMA / EclEmma (free yet powerful code coverage tool) for Visual Studio and C# code? ...

Ratio of time spent on coding versus unit testing

What is a typical estimate for coding unit tests given an estimate for coding new functionality? Is this different for estimates to maintain code? ...

Are there shortcut keys for ReSharper's Unit Test Runner?

For obvious productivity reasons, I make an effort of learning and using as many of the keyboard shortcuts for the various Re# commands. However, it seems that the unit test runner does not have any associated shortcut keys. I want to be able to select certain tests and be able to run or debug them without resorting to grabbing the mou...

How do you set up database testing using the PHP SimpleTest framework

I am using SimpleTest, a PHP-based unit testing framework. I am testing new code that will handle storing and retrieving website comments from a database. I am at a loss for how to structure the project to test the database access code. I am looking for any suggestions as to best practices for testing db code in a PHP application. Examp...

Should you display what's happening in the unit test as it runs?

As I am coding my unit tests, I tend to find that I insert the following lines: Console.WriteLine("Starting InteropApplication, with runInBackground set to true..."); try { InteropApplication application = new InteropApplication(true); application.Start(); Console.WriteLine("Application started correctly"); } catch(Exception...

Why should I both Unit test AND Web test (instead of just web test)?

My current position is this: if I thoroughly test my ASP.NET applications using web tests (in my case via the VS.NET'08 test tools and WatiN, maybe) with code coverage and a broad spectrum of data, I should have no need to write individual unit tests, because my code will be tested in conjunction with the UI through all layers. Code cov...

ASP/NET MVC: Test Controllers w/Sessions? Mocking?

I read some of the answers on here re: testing views and controllers, and mocking, but I still can't figure out how to test an ASP.NET MVC controller that reads and sets Session values (or any other context based variables.) How do I provide a (Session) context for my test methods? Is mocking the answer? Anybody have examples? Basically,...

Unit testing error conditions - EINTR

In short, how do you unit test an error condition such as EINTR on a system call. One particular example I'm working on, which could be a case all by itself, is whether it's necessary to call fclose again when it returns EOF with (errno==EINTR). The behavior depends on the implementation of fclose: // Given an open FILE *fp while (fclo...

How can I run all JUnit unit tests except those ending in "IntegrationTest" in my IntelliJ IDEA project using the integrated test runner?

I basically want to run all JUnit unit tests in my IntelliJ IDEA project (excluding JUnit integration tests), using the static suite() method of JUnit. Why use the static suite() method? Because I can then use IntelliJ IDEA's JUnit test runner to run all unit tests in my application (and easily exclude all integration tests by naming con...

Unit Testing Frameworks for C

I've seen a few questions specific to C++, but I'm really curious about C. I'm trying to add a standard unit test framework into our build environment. My primary goals are to encourage our developers to write unit tests, and to standardize those test so others can run them. Ideally I'd like to run the unit tests as part of our nightly b...

(C#) Get random data using Generics

One of our unit tests is to populate properties within our business objects with random data. These properties are of different intrinsic types and therefore we would like to use the power of generics to return data of the type you pass in. Something along the lines of: public static T GetData<T>() How would you go about approaching ...

Python, unit-testing and mocking imports

Hello, I am in a project where we are starting refactoring some massive code base. One problem that immediately sprang up is that each file imports a lot of other files. How do I in an elegant way mock this in my unit test without having to alter the actual code so I can start to write unit-tests? As an example: The file with the funct...

What would you do when you are about to add some new features to a large (and dirty) codebase which has virtually *NO* unit-testing code?

Martin Fowler says that we should do refactoring before adding new features (given that the original program is not well-structured). So we all want to refactor this dirty codebase, that's for sure. We also know that without unit-testing code it's very easy to introduce subtle bugs. But it's a large codebase. Adding a complete suite of...

Mocks or real classes?

Hi all, Classes that use other classes (as members, or as arguments to methods) need instances that behave properly for unit test. If you have these classes available and they introduce no additional dependencies, isn't it better to use the real thing instead of a mock? ...

Converting a home-brew test application to a standard unit test framework

I've got a LOT of tests written for a piece of software (which is a GREAT thing) but it was built essentially as a standalone test in C#. While this works well enough, it suffers from a few shortcomings, not the least of which is that it isn't using a standard testing framework and ends up requiring the person running the test to commen...

obtain command line arguments in unit test

In a Test project in Visual Studio 2008 (Pro), I created a Test project, and I want to configure the project properties to give a command line argument to the tests. I set the properties, but then realized I have no idea how to actually use the argument. How do you get the arguments from MSTest? ...