I love unit tests and use them whenever possible. But in the end, there’s no substitute for a full scale system test. Only after system testing, you can be sure that everything works as intended. When I was looking for a way to test a REST-style JSON web service, I decided to create a small testing framework to simplify the task.
The result is the JSysTest framework written in Java. Using JSysTest, you can create functional web service tests based on JUnit 4 and its Hamcrest-based assertion DSL. With the help of some custom matchers, a test can look as concise as this:
Have a look at the Documentation for a few more examples.
The framework is still in its early stages of development and is likely to change. I still don’t know how to make HTTP POST and PUT methods as elegant as the GET case, but I’m sure a pattern will emerge at some point.
I think the most important lesson to take away from this little experiment is that you can simplify your tests significantly if you invest a bit of time for building a highly specialized DSL.