Pickles Pro Blog .NET BDD from the trenches

Quick Tip for the Automation Layer

Automation Layer code is just like any other piece of code. That means all the same rules apply to make it “good” code: SOLID Principles, refactoring, and good naming of variables to name just a few. Today’s post is about the latter: good naming of variables.

It is important that the names of variables express the purpose of the variables. Nowhere is this more important than when comparing values. Consider this snippet:

What does p0 mean? An integer called i is just about understandable, but rather lazy. i expresses the actual result, and p0 expresses the expected result. That gives us:

Thanks to the clearer variable names, we now notice that we made an error when calling the assertion: Assert.AreEqual takes the expected value as the first argument and the actual value as the second argument. That’s very confusing, see my post about using assertion libraries for a better way of writing this.

After correcting the order of the parameters, we end up with:

But again, consider using an assertion libraries to more clearly express your intention when writing assertions.

Dirk Rombauts

Dirk Rombauts is a Software Developer with more than 10 years of experience working in .NET. He has been working with Behaviour Driven Development for several years now and thinks it is the best thing to happen to software development since the invention of coffee.

He is the maintainer of Pickles, the open source Living Documentation generator and is in the process of setting up Pickles Pro, a company that aims to make you self-sufficient in all matters BDD.