Unit testing ServiceStack applications
In this recipe we'll focus on simple techniques to test individual units of code within a ServiceStack application. We will use the ServiceStack testing helper BasicAppHost
as an application container, as it provides us with some useful helpers to inject a test double for our database. Our goal is small; fast tests that test one unit of code within our application.
Getting ready
We are going to need some services to test, so we are going to use the PlacesToVisit
application. If you are starting your own project from the beginning, refer to Creating a ServiceStack solution with Visual Studio and NuGet in Appendix A, Getting Started for information on how to get ready with Visual Studio and ServiceStack. This also covers basic usage of NUnit
, the unit testing framework we will be using in this recipe.
How to do it…
Create a new testing project. It's a common convention to name the testing project
<ProjectName>.Tests
—so in our case, we'll call itPlacesToVisit...