Tuesday, 29 April 2014

Readable Tests

It is good practice to make tests readable, your QA will thank you for this.
With this in mind we try to give our tests meaningful names. "Thanks," declares your colleague, "I now know what it is supposed to do". Everyone's happy. But will the QA or person reviewing the test suite know whether it does what it is supposed to do? If they cannot read the code then the answer is probably no.
Some of the tests that I have written in the past have used regular expressions, but I have been made aware that not everyone is comfortable translating these. So wouldn't it be nice if we could make the regular expression more 'Verbally Expressive'?

Enter Verbal Expressions...

The 'Verbal Expression' library is very good at removing the obfuscation from regular expression matching. In case you’re interested it is still regex, it’s just wrapped to make it ‘Fluent’. (see Martin Fowler - FluentInterface)

Here is an simple example of how it could be used to aid the readability of a test:
public void Convert_GivenTwoValues_TheFirstValueIsAPrefixToTheSecondValue()
    object[] collection = new object[2];
    collection[0] = "£";
    collection[1] = "100";

    CurrencyMultiValueConverter multiValueConverter = new CurrencyMultiValueConverter();
    var convertedValue = multiValueConverter.Convert(collection, null, null, System.Globalization.CultureInfo.CurrentCulture);

    VerbalExpressions verbalExpressions = new VerbalExpressions();

    Assert.IsTrue(verbalExpressions.Test(convertedValue.ToString()), "The Returned format was not as expected.");
I've used this, and quite like it, although it is at odds with the Regex Builder that I use as my regex test development tool.Regex Builder
Have fun!!


Okay, so we all know about Martin Fowler's classic 'Refactoring', but what you may not realise though is that there is also a website to back this book up containing an online summary of the refactoring in the book.

I recommend viewing the catalogue page which provides a brief summary of each refactoring. It has recently had an overhaul, and includes links to the relevant pages of Safari Books Online.

If there is enough demand, ask if the IT department manager fancies investing in a group license for safaribooksonline.

Understanding Install Log Files

Sometimes installers fail. This means that you (or one of your colleagues) will need to work out why.

The Hard Way

One option is to manually parse the rather large log file. Searching the file for the word 'Error' or 'Return Value 3', and hoping that the first instance of this will eludes to the issues via an error code.

The Easier Way

Another option that you have, is to allow part of the Windows SDK to do the legwork for you.

This utility will allow you to directly step through any errors, providing possible solutions associated to them.

You can also launch a html log file parser from this utility, which will colour code the log file, based on log type, and allow you to step between errors whilst being able to see the context in which the error was raised. 

Inspecting log files isn't fun, but it needn't be hard work either :)

Free ebook: .NET Technology Guide for Business Applications

Most people love a freebie.
Some people like reading.
These links are for those that fall into the intersecting group.
Free ebook: .NET Technology Guide for Business Applications - Microsoft Press - Site Home - MSDN Blogs