Category Archives: testing

August, 2012

Testing routes in ASP.NET Web API

Because it can be really helpful

The question that often comes up when talking to developers and clients about Web API solutions is how exactly should you go about testing your route configuration in Web API? Some would perhaps argue that in certain cases, especially if you stick to RESTful approach, this type of testing wouldn’t even be necessary, because the convention over configuration provided by the framework means that you effecitvely end up testing something that’s internal working of Web API.

With that said, especially when you have complex routes, or when you break the Restful approach and provide RPC-style API, or if you have your API actions decorated with HTTP verbs that don’t match the action names, you probably want to (and probably should, if you ask me) test the API routing to make sure certain requests end up in proper places.

Let’s deal with this interesting problem.

Continue reading

July, 2012

Run your favorite unit testing GUI directly from Visual Studio

Because it is easy and productive

If you are working a lot with unit tests and somehow are allergic to command line testing (I, for one, am) there is an easy way to configure your test project’s build to start your favorite’s library GUI automatically and load the test assembly into it.

This is very convenient and, as a bonus, allows you to set breakpoints in the test code, without having to attach to any processes.

Let’s have a quick look at how you can do that for xUnit and nUnit.

Continue reading

June, 2012

ASP.NET Web API integration testing with in-memory hosting

Because lightweight in-memory server is what the doctor ordered

In-memory hosting is one of the hidden gems of ASP.NET Web API. While the community, forums, bloggers have been buzzing about web-host and self-host capabilities of Web API, aside from the terrific post by Pedro Felix, very little has been said about in memory hosting.

Let me show you an example today, how a lightweight Web API server can be temporarily established in memory (without elevated priviliges, or cannibalizing ports like self host) and used to perform integration testing, allowing you to test almost the entire pipeline, from the request to the response.

Continue reading