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
Tag: Unit tests
Book review: Modern C++ Programming with Test-Driven Development
I’m always looking for ways to learn more about unit testing and TDD, I was elbow deep in a C++ project and I was looking to learn more about the tools & tricks of TDD in the unforgiving C++ world when this book was published and so I’ve started reading it. This book does … Continue reading Book review: Modern C++ Programming with Test-Driven Development
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
Create live templates using Resharper
From time to time I find myself writing the same code – a task I find boring, tedious and error prone(I’m not talking about code duplication – which should be eliminated as the evil it is) as the lazy developer that I am I prefer to let a tool perform these tasks for me. Today … Continue reading Create live templates using Resharper
How to write a unit test
Last week I had the pleasure of participating in Sela Developer Practice. Before my session I sat through Gil ZIlberfeld’s session “7 steps for writing your first unit test” and I found myself thinking – what are steps I take when writing a new unit test?I’ve been writing them for so long and never noticed … Continue reading How to write a unit test
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
nCrunch review – TDD on steroids
Any project that uses unit tests gets to the stage where running all of the tests takes a lot of time. Even if you manage to keep your test suite in a manageable size From time to time a developer would “forget” to run all the tests before commit and break the build. One solution … Continue reading nCrunch review – TDD on steroids
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
Why you need to make your tests fail
Test Driven Development (TDD) have many benefits. For start it’s a design methodology that help avoiding “Analysis paralysis” and make sure that you only have the needed code to solve a problem.Yesterday I found another benefit of writing the tests before the code – you get to see them fail!A while back I wrote about … Continue reading Why you need to make your tests fail