dimanche 15 avril 2018

Should unit tests use absolute values?

I came along a unit test for a method that does mapping between two classes.

@Test
public void testMapping() {
    MappingClass mappingClass = new MappingClass();
    FromClass fromClass = new FromClass("string.value");

    ToClass toClass = mappingClass.map(fromClass);

    assertEquals(fromClass.getStringValue(), toClass.getMappedStringValue());
}

The getter coincidentally contains the same string value and I believe the code was written like this because the writer knew the map method would call the getter. Exactly for this reason I would expect the absolute value, since from a TDD perspective, you're supposed to be unaware of the implementation.

Should a unit test always evaluate the absolute value of the subject instead of a derived value?

Aucun commentaire:

Enregistrer un commentaire