Blog Archives

Testing every implementer of an interface with the same tests using NUnit

You have an interface and multiple implementers of that interface. You want to test all those implementing classes using the same tests. And you do not want to repeat yourself. That would be … like … Gah!

Using a unit test framework like NUnit that is a breeze.

Read more ›




How to test a class hierarchy without repeating yourself

You don’t want to spend your effort on futile tasks. And testing all methods of a base class and then testing them again for every descendant sounds futile.

After all, non virtual methods are not going to change in a descendant, so, really, testing the base should be enough?

Read more ›




Three reasons why it is hard to get people to adopt better practices

1. Simple <> Easy

Good practices often revolve around making things simpler, making them less convoluted and complicated, putting everything in its own place instead of letting stuff spread around.

Simple does not mean easy though.

Making something simpler is hard work. Untangling a big complicated mess takes significant cognitive effort.

Read more ›




Property.Settings.Default makes it hard to unit test any method that uses it

Storing your application and user settings should be a solved problem. After all, we have done it since the dawn of software development. Yet, the question “What is the best way to store settings?” keeps cropping up. The answers vary widely and quite often spark religious wars.

As interested as I am in why people are so invested in whatever they use,

Read more ›




Why it pays to read more than just the first compiler message

Error messages are frustrating. Especially when you can’t figure out why you are getting them.

Take this bit of code:

It produces a ‘TestProject.ComparingCollections.SimpleDataAccessLayer_Tests.MountainComparer’ does not implement inherited abstract member ‘System.Collections.Generic.Comparer<ActualProject.ComparingCollections.Mountain>.Compare(ActualProject.ComparingCollections.Mountain, ActualProject.ComparingCollections.Mountain)’ error for the MountainComparer class.

Wah?

What do you mean?

Read more ›




Why it pays to invest some time learning the syntax and terminology of a language

Syntax is boring. Absolutely boring. So is theory and terminology. But neither is trivial. And neither is superfluous. Not if you want to get up to speed as quickly as possible.

Syntax differs from language to language. Everybody accepts that. Not everybody is as aware that while the concepts of object orientation are the same across object oriented languages,

Read more ›




Why CollectionAssert.AreEqual fails even when both lists contain the same items

Last time you did this, it worked flawlessly. The test you made verified that an item was added and then returned correctly:

  • Retrieve all items into a “before” list.
  • Add an item.
  • Retrieve all items into an “after” list.
  • Manually add the item to the “before”

Read more ›




Testing an abstract base class – code example

In the “How do I test an abstract base class if I can’t instantiate it?” post, you found out that you can actually test an abstract base class even though you can’t instantiate one.

The “all you need to do is” end of the post, however,

Read more ›




Test Driven Development: stacking bricks or turning on lights

After all the good things you heard about it, you have taken the plunge and are taking your first steps in test driven development. You thought about what your Splendiforous class is supposed to do, wrote the tests and grew the implementation for all its methods.

This TDD thing really makes sense.

Read more ›




How does my mock know what value I want?

It is early afternoon. You just started your job at Glamorous Inc. Your buddy this morning talked about unit tests. How they want all code to have unit tests but also have code that was written before they started doing that. And they want you to start by getting some of that code under test.

Read more ›




Show Buttons
Hide Buttons