Testing ASP.NET MVC Routes (Both Web and API)

Lately, I was working on an ASP.NET MVC web application, and one of the questions that came up to me was: How do you deal with the application’s routing table when it comes to Unit Testing and Test-driven Development?

Routing is one of the areas of your application that can easily be screwed up – and these errors then have a high likelihood to go unnoticed and make it into production. And because even small to mid-size web projects will have dozens or even of hundreds of possible URLs I find it important to have a quick and reliable strategy to deal with such a scenario (covering a bulk of URLs through tests).

Read More

A Handy IIS Express (Test) Helper Class

Oftentimes, when developing or integration-testing a piece of software that is web-based (for example a web site or a web service component such as an Azure Mobile Service), being able to start and stop a web server programmatically on an as-needed basis comes in very handy.

This is where IIS Express comes into play. IIS Express basically is a lightweight, self-contained version of his big sibling, the fully fledged Internet Information Server. Because it doesn’t run as a service and doesn’t require administrator rights, it is ideally suited for developing and testing web sites and services locally – just like Visual Studio starts an instance of IIS Express when you hit F5 on a web application/service.

This post presents a helper class to programmatically interact with the IIS Express web server.

Read More

An introductory presentation about testing with MSTest, Visual Studio, and Team Foundation Server 2010

Note
I originally wrote this post back in February 2011 over at my old blog at geekswithblogs.net. Because it still receives some hits, I decided to take it with me and copied it to my new blog. With the exception of some necessary HTML polishing, this article is unchanged compared to its previous version.

While it was very quiet here on my blog during the last months, this was not at all true for the rest of my professional life. The simple story is that I was too busy to find the time for authoring blog posts (and you might see from my previous ones that they’re usually not of the ‘Hey, I’m currently reading X’ or ‘I’m currently thinking about Y’ kind…).

Anyway. Among the things I did during the last months were setting up a TFS environment (2010) and introducing a development team to the MSTest framework (aka. Visual Studio Unit Testing), some additional tools (e.g. Moq, Moles, White), how this is supported in Visual Studio, and how it integrates into the broader context of the then new TFS environment.

Read More

It’s the maintenance, stupid! (or: Something is rotten in developerland.)

Note
I originally wrote this post back in January 2010 over at my old blog at geekswithblogs.net. Because it still receives some hits, I decided to take it with me and copied it to my new blog. With the exception of some necessary HTML polishing, this article is unchanged compared to its previous version. – And why would I change it, anyway? I still agree with every single sentence – except the last one, for obvious reasons :-)…

Most people – even the overwhelming majority of programmers – would say that the main activity of a software developer is “writing source code”. But this is a (though quite understandable) misconception – and if you take a look at the available figures on the issue or if you – as a software professional – are honest to yourself, the misconception immediately turns out to be an enormous one.

The world is full of software systems that are already in operation, and they have to be maintained – writing a new software system from scratch is a rare highlight for most software developers. On the other hand, the importance and especially the business value of maintenance is greatly underestimated,  as well as the amount of actual working time spent on it. I think the main reason for this misperception lies in the fact that maintenance activities are spread over a much longer time span compared to the far more intense development period. Also, maintenance costs per year are relatively lower than the initial development costs.

Read More

TDD is not about testing, it’s about how we develop software

Note
I originally wrote this post back in November 2009 over at my old blog at geekswithblogs.net. Because it still receives some hits, I decided to take it with me and copied it to my new blog. With the exception of some necessary HTML polishing, this article is unchanged compared to its previous version.

I am practicing Test Driven Development (TDD) now for some two years or so, and soon this technique of writing software felt so natural, that I hardly could imagine doing it another way or even imagine a reason why I should do so. But on the other hand, I know that not questioning something anymore and not being self-critical from time to time is a certain recipe for running into a disaster sooner or later. So I asked myself: What makes TDD such a natural way of writing software? and What are your main conceptions about TDD? This post is the result of my reflections.

Read More

Unit testing StyleCop rules

Note
I originally wrote this post back in November 2009 over at my old blog at geekswithblogs.net. Because it still receives some hits, I decided to take it with me and copied it to my new blog. With the exception of some necessary HTML polishing, this article is unchanged compared to its previous version.
The Gallio testing framework (which essentially is MbUnit) that I was using at this time, is no longer available. But it’s very similar to NUnit and you can easily read the code samples if you’re familiar with NUnit. I updated the accompanying sample solution to use NUnit (but not the code excerpts in this post). Also, I updated it to VS 2013 and NuGet and gave it a new home on Github.)

One of the single most influential cost factors for software projects is code readability and understandability – and the most important factor for readability in turn lies in the adherence to Coding Style Guidelines. To enforce such guidelines, Microsoft has provided a free tool which checks a given set of source code files against a given set of style and consistency rules: MS StyleCop. The tool comes with quite a lot of predefined rules – however, they mirror the coding practice at MS and not all of them may be appropriate or sufficient for others. Therefore, StyleCop allows for authoring custom rules to extend or modify the original set of rules. How this can be done, is well covered elsewhere on the web (e.g. herehere, or here).

But in contrary to the rules authoring issue, very little – almost nothing – can be found that deals with testing issues. All I found was this post, which gave me a first insight into the issue and inspired me to write a custom Gallio/MbUnit test fixture that lets you write tests against StyleCop rules as simple as this:

Read More