Tag Archives: REST

Readable Java system tests with good old JUnit

Posted on by

This article is the third in a series about system testing:

  1. Dockerized testing vs end-to-end testing
  2. How to setup Dockerized testing
  3. Readable Java system tests with good old JUnit

JUnit is poorly named. Given the name, people tend to think that it should only be used to write Java unit tests. And then people feel a bit hesitant about writing their integration tests with JUnit too. When they start with system tests, they often think they need another driver for their tests. Sure, maybe using another abstraction layer and a custom domain specific language (BDD), you can make the tests more readable for a non-programmer. That often comes at the cost of making the tests less readable for the programmers. And if we are honest, who’s going to read the tests the most? Perhaps just naming test classes and methods well and writing readable code can suffice?

read more »

JAX-RS: RESTful Web Services

Posted on by

Draft specen för JAX-RS: The Java API for RESTful Web Services släpptes för någon vecka sedan. Som oftast brukar jag inte orka granska specarna som kommer, men denna gång tog jag mig en titt. It made me go mmmm… som det heter. Kan denna lilla kodsnutt väcka aptiten:

@UriTemplate(“widgets”)‏
public class WidgetList
{
@HttpMethod
@UriTemplate(“offers”)‏
WidgetList getDiscounted() { /* ... */ }

@UriTemplate(“{id}”)‏
Widget findWidget(@UriParam(“id”) String id)‏
{
return lookupWidget(id);
}
}

Här är en annan goding:

@UriTemplate(“widgets”)‏
@ProduceMime(“application/widgets+xml”)‏
public class WidgetList
{
@HttpMethod
String getAll() { /* ... */ }

@HttpMethod
@UriTemplate(“{id}/description”)‏
@ProduceMime(“text/html”)‏
String getDescription(@UriParam(“id”) String id) { /* ... */ }
}

Men, gräver man djupare i specen (den är hittills bara ~30 sidor) så blir det mer hmm… än mmm… massor av rätt märkliga begrepp som jag aldrig stött på tidigare. Speciellt begreppet Contract i detta sammanhang förvirrar mig ganska mycket. Hur som helst, väl värt en titt. Kanske en RD på ämnet?