Skip to Content

Unit test verbosity

Here is a sample test method I found in one of my customer’s codebase. What do you think? What’s the minimum number of lines really needed to write the exact same test?

The sad thing is that, in the codebase, there are hundreds of tests like this one. All copy/pasted from the same verbose template.

public void testGetCustomerOK() {"======= testGetCustomerOK starting...");

  try {
    CustomerDTO targetDTO = this.serviceImpl.getCustomer("ABC99");

    // Vérifier.
    Assert.assertNotNull("Extra non trouvé.", targetDTO);
    Assert.assertEquals("Les accountId doivent être identiques.",
	    "ABC99", targetDTO.getAccountId());

  } catch (CustomerBusinessException exception) {
    LOGGER.error("CustomerBusinessException : {}",
  } catch (UnavailableResourceException exception) {
    LOGGER.error("UnavailableResourceException : {}",
  } catch (UnexpectedException exception) {
    LOGGER.error("UnexpectedException : {}" +
  } catch (Exception exception) {
    LOGGER.error("CRASH : " + exception.getMessage());;
  }"======= testGetCustomerOK done.");
comments powered by Disqus