In Defence of Testing One Thing Per Test Method

In my last post, I described why I prefer tests that test only one thing. Naturally, this can lead to a lot of test methods with a fair amount of repetitive code. I presented a technique for programmatically generating tests when doing so by hand would be tedious or error…

Programmatically Generating Tests Using a Visual Studio T4 Text Template

Erik Dietrich's blog series on unit testing is my favourite introduction to test-driven development (TDD). It is concise, enjoyable to read, and unlike a lot of introductions to TDD that only describe how to write tests, his series focuses on practical considerations like naming tests, test structure, build integration, and…

Revisiting Test Context Classes in C++

In an earlier post, I described how I like to use disposable objects when writing functional tests in C#, to reliably cleanup resources and to promote code reuse across tests. I’ve been writing more tests in C++ recently, so I thought I would revisit the concept of resource-context classes…

Practical Considerations for Using Disposable Resource-Context Classes for Functional Tests in C#

In my previous post, I described how I use disposable classes to handle complex initialization and cleanup for functional tests in C#. In this post, I’ll cover some practical considerations for using these contexts. Using Multiple Contexts Some tests require multiple resources. For example, a test that lists all…

Disposable Resource-Context Classes for Functional Tests in C#

Automated tests generally follow the Arrange, Act, Assert pattern. First, establish the preconditions of the test, then execute the functionality under test, and, finally, assert that the result meets the expectation. The Arrange portion of a unit test is usually trivial. Functional tests, however, can often have fairly involved preconditions…

Reflections on Enforcing Coding Style to Commit Code

I was recently part of a team implementing a new cloud service. One of the objectives of this team was to frequently release software to production. This might be a minor patch or the introduction of a significant new feature. After some careful investments in automated builds, deployments and tests,…

Writing Automated Tests for Custom Windows Performance Counters

As I mentioned in my previous post, I really like using Windows Performance Counters in automated tests to gain insights into applications. It is not difficult to expose custom Performance Counters from your own application to report various metrics. But what about testing these custom counters? Like any other component…

Tricks with Windows Performance Counters for Automated Tests

I really like Windows Performance Counters. I find them a powerful tool for understanding applications under development and for monitoring and troubleshooting applications in production environments. Windows Performance Counters are available for reporting absolute values (e.g., Memory\Available Bytes), counts (e.g., Network Adapter\Packets Received Discarded), rates (e.…

Tests That Involve Time Are Hard

I've written a lot of automated tests that involve time and time-series data. I've also maintained many similar tests written by others. Given that these tests involve time and sometimes subtle timing, they can often be less deterministic than tests that only involve static data. I've written tests that passed…

Avoid Handling Exceptions in Negative Tests

Unit tests that provide coverage for every exception a method can throw are invaluable. When writing these tests, the developer needs to carefully consider (or reconsider) the exceptions being thrown, along with how they will ultimately be handled by the caller. This exercise alone often results in improvements to the…