Tuesday, October 26, 2010

Multiple unit test inheritance with JExample

Two months ago I wrote about JExample (see Specifying unit test dependencies with JExample). At the time, my examples did not include multiple unit test inheritance, but was informed later by @jexample that is possible. I just got time to try it in the Oscar project:
@Test public Oscar testConstructor()
throws URISyntaxException
  Oscar oscar = new Oscar();
  return oscar;

public String testNormalize(Oscar oscar)
throws URISyntaxException
  String input = oscar.normalize(
    "This is a simple input string with benzene."
  return input;

public List testTokenize(
  Oscar oscar, String input) throws Exception
  List tokens = oscar.tokenize(input);
  Assert.assertNotSame(0, tokens.size());
  return tokens;

public List testRecognizeNamedEntities(
  Oscar oscar, List tokens)
throws Exception
  List entities =
  Assert.assertEquals(1, entities.size());
  return entities;

The pattern here is that each test method returns one variable, so that any method depending on two other unit test will have two parameters. The order is defined by the order in which they are given by the @Given clause.