New Project: JSysTest

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:

  assertThat(get("/some-resource"), has(status(404)));

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.

Advertisements
This entry was posted in java and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s