Database tests

Database tests are a type of automated tests that do not get enough love these days. Everybody is talking about unit tests, acceptance tests, integration and regression tests.

Database tests have gotten a bad reputation because of supposed unit tests which test functionality through the DB. They pretend to test some kind of model by reading from and writing to the DB. Those are not database tests (and those are not models, by the way). So what is a database test and where does it fit in?

Expecting Exceptions

Most test tools provide the developer with means to suggest that a test should expect an specific exception. For instance, JUnit the prevalent test tool for the Java language provides an annotation to mark such a test (from the JUnit 4 documentation):

    public void empty() {
         new ArrayList<Object>().get(0);

The annotation marks the method as a test and the parameter “expected” tells JUnit which exception type to expect.

Separating the Application from the Environment

A useful pattern for developing testable rich client GUI applications is the *[Humble Dialog Box](* by Michael Feathers. I have used variations of it for *[TDD]( "Test Driven Development")* style development of all kinds of Windows programs. It boils down to have a rather dumb view (the humble dialog box) that delegates the handling of its events to a controller object.

A Generic WPF-Control

There are several ways to reference generic types from XAML for bindings. Unfortunately there is no way to define a generic type using XAML.

I needed to port a fancy dialog for selecting from a list of items from Winforms to WPF. The original dialog had a generic type parameter for the type of the items. Something along the lines of public class SelectionDialog<TItem> : Form. This is not possible if you want to design the layout of a control with XAML, because the XAML type definition does not allow to define type parameters.

Custom Field Handlers for Views 2 (Drupal)

This is a step-by-step example how to create custom field handlers for Views 2 for Drupal. I needed this information myself and all I could find was not going very deep, at least not as deep as I needed it. I learned all the necessary details by reading other handlers that came with the views module (in views/modules) and by extensive use of print_r().

Does TDD lead to inefficient algorithms?

Bob Martin showed in a recent blog post "Echoes from the stone age" how TDDing a sorting algorithm would lead to good ol' bubble sort. That stirred up a heated discussion if TDD is really worth it, if it leads to "inefficient" algorithms.

Implicit Type Parameter for Implementing Type

A while ago I had an interesting twitter discussion with Chris Ammerman (@cammerman) about type parameters of generic interfaces (C#). Chris tweeted "I often encounter a situation where I want a generic interface, but the type param should ALWAYS be the type of the implementing class". One example of this is ICloneable.

Subscribe to Eric Schäfer's Blog RSS