All new code must have a complete set of unit tests. The majority of the following standards stem from the work of Roy Osherove and his book The Art of Unit Testing When is a test not a unit test? A test is not a unit test if: It talks to the database It communicates across the network It touches… Read more →
Category: TDD
3 Little Pigs
The fable of the 3 little pigs was written using what is now known as the the rule of 3. This simple principle has been used countless times and is as effective today as it has ever been. We are not limited to two polar opposites when developing software: quick to write; hard to change or slow to write; easy… Read more →
Service Factory Template for Test Classes
private static IService CreateService(params object[] instances) => new Service( instances.OfType<IDependency1>().SingleOrDefault() ?? new StubDependency1(), instances.OfType<IDependency2>().SingleOrDefault() ?? new MockDependency2()); Read more →
Migrating from NUnit to xUnit
These regular expression came in handy recently – they’re not perfect, in particular a couple of the second grouping need to be more greedy – but I did the migration first time through so didn’t get to improve them. Find: Assert.That((.+?), Is.EqualTo((.+?))) Replace: Assert.Equal($2, $1) Find: Assert.That((.+?) == (.+?)) Replace: Assert.Equal($2, $1) Find: Assert.That((.+?), Is.StringContaining((.+))) Replace: Assert.Contains($2, $1) Find: Assert.That((.+?).Contains((.+)))… Read more →
Multiple Dispatch, Double Dispatch and the Visitor Pattern
I’ve been looking into the Visitor pattern and figuring out how to make it work with overloaded methods. Starting with the abstractions interface IVisitor { void Visit(AbstractElement element); } abstract class AbstractElement { public void Accept(IVisitor visitor) { visitor.Visit(this); } } And initial implementations class TestElement1 : AbstractElement { } partial class TestVisitor1 : IVisitor { public string visitedMethod =… Read more →
More TDD Kata’s
The Bowling Game Kata Gutter game scores zero – When you roll all misses, you get a total score of zero. All ones scores 20 – When you knock down one pin with each ball, your total score is 20. A spare in the first frame, followed by three pins, followed by all misses scores 16. A strike in the… Read more →
TDD – getting started
It’s not TDD, it’s design by example http://stackoverflow.com/questions/2512504/tdd-how-to-start-really-thinking-tdd … I write a test that starts by ‘newing’ up a class that doesn’t exist. It won’t compile. (red) So, I create an empty class so it compiles, and succeeds. (green). I call a method on the class, it doesn’t yet exist and won’t compile. (red) I right click, “generate method”. Compile,… Read more →