An atomic method updates dozens of properties. Am I "testing too much"?

by usr-local-ΕΨΗΕΛΩΝ   Last Updated July 11, 2019 16:05 PM - source

This question is about designing unit tests, something I started learning short ago.

I know the principle that if you are testing too much in a single unitary test it is a smell, either of code or design itself.


I am computing a tax return form based on tax figures computed over the course of a year. Those figures are stored in the database in different rows on a monthly basis.

In order to compute the figures for the tax returns, some columns have to be copied "in the right place", other have to be summed up across 12 months.

The final form has a set of few flat columns, a Map divided by month with 10 columns for each entity and another Map that is a view on a different aggregation (hence the sum), where each entry has 4 columns.

Mocking the database is a joke, so I have a consistent set of tax figures along with the expected results hardcoded (this is a kind of code duplication I like to implement).

The problem here is that while I am still writing test code I discover myself writing a lot of testing code.

The method that computes the form should be atomic (i.e. set all the columns at once) because it runs in a single transaction creating a new consistent object, but is all about setting dozens of different columns. I have ended up testing more than 30 different properties.

Simple question

  • Given that my unitary method works on columnA..columnZ at the same time
  • Given that failure of one assertion (thanks to Junit's ErrorCollector) causes the test to fail but evaluates and reports other failed assertions all together

From the test design perspective, and in particular to the principle "don't test too much", is it preferrable to...

  1. Write a single test that performs 26 assertions each every column?
  2. Write multiple tests that run the same method with the same data set but each tests the outcome of a very single property of the output?
  3. Other strategy?

Pseudo code

The following is a sample of how the current code is structured. I really have plenties of assertions

public void testCreateTaxForm(){

    //Create the mocks, e.g.
    MonthlyDao dao = mock(MonthlyDao.class);

    TaxFormManager uut = new TaxFormManagerImpl();

    TaxForm form = uut.create(....);



    //Following is wrapped in a method for my comfort
    for (Month month: Month.values()) {

    for (ExemptionType exemption: ExemptionType.values()) {


Pseudo alternative

In the pseudo alternative, I would have to write dozens of different methods (at least 120, each testing a column in a month) trying to reuse as most initialization logic as possible to avoid the test code base to grow too fat.

public void testTaxReturn_flatColumnA
public void testTaxReturn_flatColumnB
public void testTaxReturn_flatColumnC
public void testTaxReturn_january_columnA
public void testTaxReturn_january_columnB
public void testTaxReturn_january_columnC
public void testTaxReturn_retirementFunds_columnA
public void testTaxReturn_retirementFunds_columnB
public void testTaxReturn_retirementFunds_columnC
Tags : unit-testing

Related Questions

Best practices on unit tests for consecutive functions

Updated November 26, 2018 22:05 PM


Updated February 18, 2017 10:05 AM

What does stubbing mean in programming?

Updated March 03, 2017 13:05 PM

Integration tests, but how much?

Updated February 28, 2017 08:05 AM