1 of 2 branches missed in Eclemma

Joaquim Maria Puyal i Ortiga picture Joaquim Maria Puyal i Ortiga · Mar 6, 2016 · Viewed 7.5k times · Source

I have an application (Spring 4 MVC+Hibernate+jpa4+MySQL+Maven integration example using annotations) , integrating Spring with Hibernate using annotation based configuration.

and this unit test

@Test
    public void testFindAll() throws Exception {
        List<Guardian> guardians = getGuardianAccessorService().findAll();
        assertNotNull (guardians);
        assertTrue    (guardians.size()>=0);
    }


@Test
    public void testFindCompanyGuardians() throws Exception {

        List<Guardian> allGuardians = getGuardianAccessorService().findAll();       
        List<Guardian> guardiansByCompany = getGuardianAccessorService().findCompanyGuardians(AUTHENTICATED_USERNAME);

        assertTrue    (guardiansByCompany.size() <= allGuardians.size());       
    }

but in this asserts lines I have the warning 1 of 2 branches missed

assertTrue (guardians.size()>=0);

assertTrue (guardiansByCompany.size() <= allGuardians.size());

Answer

eckes picture eckes · Mar 7, 2016

Not sure if it makes sense to actually run branch (or line) coverage on your unit tests. You should mainly inspect your target under test, not the tests. It is expected that if your tests do not fail that the fail brach is not taken, and this is reported as partial coverage.