The problem with unit tests is that they keep on breaking…Obviously that’s not entirely correct, nevertheless I had the pleasure of hearing the sentence above numerous times. It’s true – unit tests do tend to fail and we prefer that they fail only when a regression occurs – when something that used to work stopped … Continue reading Creating robust tests with Isolator V7
Tag: C#
Refactor “if” statements – functional programming style
Have you ever seen code that look like this: public string GetStatusDescription(Model model){ if(model.HasProblemReports) { return "Errors"; } if(model.SystemState.WorkingMode == WorkingMode.NotManaged) { return "Manual"; } if(model.SystemState.IsInitializing) { return "Initialize"; } if(!model.SystemState.InService) { return "Not in service"; } if(model.SystemState.WorkingMode == WorkingMode.Paused) { return "Paused"; } if(model.Storage.Objects.Any(obj => obj.IsMoving)) { return "Movement in storage"; } return string.Empty;}I … Continue reading Refactor “if” statements – functional programming style
List executed code using PostSharp
This post was created to answer a question by Laimonas Simutis on the ALT.NET mailing list – how to list all executed code…There where many good ideas and your truly suggested using PostSharp – mainly because this is one of the examples I use in my AOP and PostSharp presentation. And so without further ado … Continue reading List executed code using PostSharp
Enabling parameterized tests in MSTest using PostSharp
I have blogged about the shortcoming of Microsoft’s unit testing framework in the past. It has very good Visual Studio (and TYFS) integration out of the box but it seems that in order to use it I have to suffer lack of functionality I’m used to taking for granted when using any other .NET unit … Continue reading Enabling parameterized tests in MSTest using PostSharp
Supercharge Isolate.Verify
At work we use Typemock Isolator for all of our Isolation/Mocking needs. Lately I’ve noticed that my co-workers do not like to use verify. One of the reasons they prefer not to use it is that sometime Verify error messages leave much to be desired. There are a few simple tricks that helps Isolator help … Continue reading Supercharge Isolate.Verify
How to return default(Type) in runtime – a TDD example in four unit tests
I’ve found this question while going over my old StackOverflow answers:I'm using reflection to loop through a Type's properties and set certain types to their default. Now, I could do a switch on the type and set the default(Type) explicitly, but I'd rather do it in one line. Is there a programmatic equivalent of default?I … Continue reading How to return default(Type) in runtime – a TDD example in four unit tests
RTFM–the tale of ReaderWriterLockSlim
The .NET BCL (Base Class Library) is readable, easy to understand and not less important documented. This is a story on where a simple reading of documentation could have saved us from a minor bug… If you’ve been using .NET you might be familiar with the ReaderWriterLock essentially a lock that enable multiple readers or … Continue reading RTFM–the tale of ReaderWriterLockSlim
Using null-coalescing to find item in multiple collections
A co-worker showed me this:var result = collection1.GetObjectByAtSpecialLocation(location) ?? collection1.GetObjectByAtLocation(parent, location) ?? collection2.GetObjectByAtSpecialLocation(location) ?? collection2.GetObjectByAtLocation(parent, location);I’m still trying to decide whether it’s a good practice and if it’s readable or not…In case you’re not familiar with ?? operator a.k.a null-coalescing operator it’s basically returns a default value if the left side is null so the … Continue reading Using null-coalescing to find item in multiple collections
Spot the bug – misbehaving server
We had a strange issue at work – we had a misbehaving server, who worked perfectly well with one client but had strange issues when several clients connected to it. The server would broadcast a message to all of its clients but only one client would receive that specific message, re-sending the message would fix … Continue reading Spot the bug – misbehaving server
Multiple asserts – done right
If you’ve been writing unit tests for some time or seen a good presentation on how to write unit tests you probably heard the “One assert per test” rule. There are real benefits in having only one assert in each tests – you get a focused tests, it’s easier to understand what caused the test … Continue reading Multiple asserts – done right