lundi 25 février 2019

How to not lose the purpose of a test case?

Looking into a code base over time, I started to worry that the test cases of it will become uninformative in the future. I foresee people in the future will ask: "What did they try to test here?"

A sample of confusing test case to me is:

public void convertAToB_unsupported() {
  String source = "src/test/data/12323.xml"
  checkNull(process(source));
}

That's it.

As for me, I usually do this way:

/**
 * Calling get into a non-empty list should give something. (TICKET-9812)
 */
public void shouldBeAbleToGetDataWhenNotEmpty() {
  // Given that the list is not empty
  List<Integer> list = new ArrayList<>();
  list.add(130);

  // When getting a data
  int first = list.get(0);

  // Then it should be possible
  assertThat(first, equalTo(130));
}

I don't know if this is sufficient or too much.

Could you share to me some best practices to ensure that the test remains informative in the future? Some links would be appreciated.

Aucun commentaire:

Enregistrer un commentaire