Blog Archives

Head scratching with a TargetParameterCountException

Ever introduced an extra parameter on a method, tracked all its usages and made the compiler happy by providing a corresponding extra argument in all the calls of that method?

Sure you have. Either that or removed a parameter from a method.

You just change the signature of the method,

Read more ›

Posted in Software Development
Tags: , , , , , , ,

Making sure all IWorker implementers call CanHandle from Handle without a mocking framework

lego-568039_1280

You have an interface that allows you to treat all worker classes – classes that handle a specific type of work – as just one type: IWorker;

You want your worker classes to be able to do their work without having to check their backs every step of the way.

Read more ›

Posted in Unit Testing
Tags: , , , , , , , , , , , ,

4 surprises with asserts moving from Delphi to C#

QuestionMark_Exclamation-Point

Moving from Delphi to C# is fun most of the time.

Discovering stuff I can do in C# that is impossible, or (very) time consuming, in Delphi is fun. Discovering that stuff I take for granted in Delphi – i.e. metaclasses (officially “class references”),

Read more ›

Posted in Software Development
Tags: , , , , , , , , ,

Verify a validation method is called that doesn’t throw exceptions

The strategy laid out in Testing strategy for validation and action methods calls for a single test per action method, to show that it actually calls the validation method.

Validation methods throwing exceptions on invalid input provide you with a handy means of checking whether it has been called by your action methods.

Read more ›

Posted in Unit Testing
Tags: , , , , , ,

Testing strategy for validation and action methods

How do you test a set of methods that call each other without repeating yourself unnecessarily?

You are more than tired of debugging “List index out of bounds”, “Duplicates not allowed” and similar exceptions. You want some help from your code so you don’t have to hit “Next” until you are blue in the face to figure out the information not contained in the standard exception messages.

Read more ›

Posted in Unit Testing
Tags: , , , , , , ,

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

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 NUnit that is a breeze. But you, you use MSTest,

Read more ›

Posted in Unit Testing
Tags: , , , , , , , , , , ,

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 ›

Posted in Unit Testing
Tags: , , , , , , , ,

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 ›

Posted in Unit Testing
Tags: , , , , , , , , , , ,

How do I make a method use a different class in unit tests?

The code you work on has this wonderful simple method. All it does is use a couple of other classes, passing through the parameters it received and setting some properties.

As it is such a simple function nobody bothered to write any tests for it. After all, “It only passes through to another class.”

Read more ›

Posted in Unit Testing
Tags: , , , , , ,

Why can’t my test access a public constructor?

It’s late in the afternoon. Almost time to go home. Just one issue to finish. A simple class that needs a couple of simple tests. Should be a breeze.

Five minutes later you are ready to bang your head against your desk. The error messages keep flying. And you can’t see why.

Read more ›

Posted in Unit Testing
Tags: , , , , , ,

Show Buttons
Hide Buttons