Faking a long running asynchronous call

A few days ago I needed to make sure that a specific method would only get called once no matter how many times it’s caller is invoked. The simplified code looked something like this:public async Task CallLongOperation(){ var result = await _client.LongWebCall(); if (result.Failed) { // log failure and exit } }I needed to make … Continue reading Faking a long running asynchronous call

One assert to rule them all

What’s wrong with Assert.XQuick – what is the different between the following two lines:Assert.IsTrue(result == expected);Assert.AreEqual(expected, result);Essentially both Asserts check for the same condition, in practice once fail we get very different error messages:While this example is easy to understand – when facing less than trivial test it can be downright impossible to understand the … Continue reading One assert to rule them all

Unit testing multi threaded code–Timers

Writing unit tests for multi-threaded is not simple and could even be impossible for some scenarios – how could you test that an asynchronous method was not called?Since most unit testing examples tend to be rather trivial I’ve decided to try and explain other more complex scenarios – preferably without using any calculator examples.The “Timer” … Continue reading Unit testing multi threaded code–Timers

Making string based method strongly typed

I can't believe they implemented this way – was the first thought on my mind…The method in question is part of the new(er) NUnit’s constraint based model specifically the one used to assert a property value.Before we dive deeper a few words on the constraint based model:constraint based modelMost unit testing framework have similar way … Continue reading Making string based method strongly typed

NUnit’s new Action Attributes is AOP to your unit tests

With the new NUnit release (v2.6) introduce a new feature called Action Attributes which means that now NUnit has rolled out it’s own mini-AOP capabilities. In the past SetUp and TearDown where used to perform actions before and/or after a test run, they worked well enough but were limited to running certain operation only on … Continue reading NUnit’s new Action Attributes is AOP to your unit tests