TDD and prototyping—a love story?

Posted on Tue 10 July 2018 in Methodology • Tagged with test, tdd, prototyping

Can you combine Test-Driven Development (TDD) with prototyping? How can you write tests for functionality that is largely unknown? Where do you even start if you’re on unfamiliar ground and you need to explore to learn about possibilities and constraints? How can you write tests when you don’t …


Continue reading

Testing asynchronous background workers in .NET

Posted on Tue 08 May 2012 in Coding • Tagged with async, background worker, test, .net

When you build a GUI, all lengthy operations that can be triggered by the user should take place on a background thread so that the GUI doesn’t become unresponsive. Why would it? Well, it’s because all GUI operations take place on a single thread - the GUI thread (the …


Continue reading

NSubstitute vs Moq - a quick comparison

Posted on Mon 27 February 2012 in Coding • Tagged with mock, moq, nsubstitute, test

When you write unit tests, you occasionally need to mock away dependencies of the subject under test (SUT). By far the easiest way to do this is to use a mocking library, which has the added benefit that it allows you to verify the behavior of the SUT by inspecting …


Continue reading

Mocking iteration over file in Python

Posted on Sat 24 December 2011 in Coding • Tagged with file, mock, test, Python

Let’s say that I want to mock reading from a file using file’s iterator capability, i.e. (simplified version):

def readfile(f):
    using open(f) as fd:
        for line in fd:
            yield line

I could mock the readfile function, but then my mock would have to replicate the …


Continue reading

Test data provider using Python metaclass

Posted on Sat 01 October 2011 in Coding • Tagged with metaclass, Python, test

In my airpnp project, I had to write a binary plist parser in order to parse certain data posted by iDevices. To support my unit tests, I created a number of binary plist files using an existing tool. I ended up with 17 files, and quickly realized that I wanted …


Continue reading

Mocking Zope interfaces

Posted on Wed 28 September 2011 in Coding • Tagged with mock, test, python

In one of my pet projects I use Twisted for handling asynchronous network events. While browsing the Twisted source code, I encountered Zope interfaces. In a dynamically typed language like Python, what good are interfaces?

It turns out that Zope interfaces are slightly different from interfaces found in a statically …


Continue reading