Home » TDD

Tag Archives: TDD

Mock Around the Clock

When I produced System Stubs I attempted, and failed, to produce a mock implementation for the system clock. It’s very convenient in production code to create a variable containing something like DateTime.now() and then perform time calculations between that instant and some other date. How Do We Mock It For Testing? I’m going to attempt to surprise you by telling ...

Read More »

Why Most Unit Testing is Waste???

A rebuttal of points raised in this article by James O Coplien. It’s worth noting that James O Coplien is a well respected father of modern software engineering, so it’s odd to be writing such a piece. Write the wrong sort of code, and the wrong sorts of tests will annoy you. The myth about good code structure The article ...

Read More »

All Our Assertion Problems

When our software outputs JSON, it can be hard to test. Consider this code: 1 2 assertThat(someJson)    .isEqualTo(expectedJson); Assuming the rendering of the resulting json matches the spacing of the expected JSON, this will work. When it doesn’t work, we get a big old string diff result telling us that the strings were different. But JSON isn’t a String What ...

Read More »

The Right Kind of Failure

Basic question: why do we write our tests first and make sure they go red? Answer: because it’s possible that a test we write to test a feature after the fact would go green anyway, because it’s not really testing the feature properly… or there’s a chance that we write a test, it fails, and then we have a lot ...

Read More »

It Looks Right To Me

When writing a test it’s important to test both positive and negative scenarios. It’s important to test edge cases. However, when choosing test data, the test data needs to illustrate the test case well. If the test data is hard to connect back to the exact use case, then it can lead someone to misunderstand the test, its implied specification, ...

Read More »

A Java Test Class Doesn’t Test a Class

If you write tests badly, you end up with a Curdled Test Fixture, where there’s an unholy mess of unrelated tests in the same class. At Interview A great job interview question is to ask someone what test automation they’ve constructed and how they came to do it. A not-great answers is “none”. In my experience, worse than that is ...

Read More »

So I Wrote a Library

If you’ve never done it, go out and find an open-source project to contribute to. Whether it’s one of your own or something you use, go and try writing code in the wide open to see how it feels. I’ve recently been working on a library of my own. I say my own. It’s actually someone else’s code that I ...

Read More »

Chasing The Dragon

Functions should, ideally return something. It makes them easier to test. Same for services in a service architecture. Bosh! Chasing The Dragon Consider a component in your software where you make a request, and it handles that request by doing some processing and then passing the data to the next component for onward processing. This might be at code level, ...

Read More »

The Three Stages of Knowledge

In software development, knowing how to do things seems to fall into three stages. Ok… let’s pretend it does, it’s bound to be more complex than this, but this is a useful model, so bear with me. Facts – you’ve read how something works and how to get going with itLots of experience driven fixes – you’ve hit some problems, ...

Read More »