tntim96 / JSCover

JSCover is a JavaScript Code Coverage Tool that measures line, branch and function coverage
GNU General Public License v2.0
399 stars 84 forks source link

Test improvement: removed Exception Handling (test smell) #292

Open eas5 opened 4 years ago

eas5 commented 4 years ago

This is a test refactoring.

Problem: The Exception Handling test smell occurs when a test method explicitly a passing or failing of a test method is dependent on the production method throwing an exception.

Solution: Use JUnit's exception handling to automatically pass/fail the test instead of writing custom exception handling code or throwing an exception. In this case, JUnit 4.13 assertThrows() was used to properly handle the expected exception.

Result: Before:

try {
    mainHelper.checkDependantClasses(dependantClasses, "MANIFEST-NO-CLASS-PATH.MF");
    fail("Should have thrown exception");
} catch(IllegalStateException e) {
    String message = e.getMessage();
    assertThat(message, equalTo("Could not find the 'Class-Path' attribute in the manifest 'MANIFEST-NO-CLASS-PATH.MF'"));
}

After:

IllegalStateException thrown = assertThrows(IllegalStateException.class, () ->
            mainHelper.checkDependantClasses(dependantClasses, "MANIFEST-NO-CLASS-PATH.MF"));
assertTrue(thrown.getMessage().contains("Could not find the 'Class-Path' attribute in the manifest " +
            "'MANIFEST-NO-CLASS-PATH.MF'"));
codecov-commenter commented 4 years ago

Codecov Report

Merging #292 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #292   +/-   ##
=========================================
  Coverage     96.16%   96.16%           
  Complexity      920      920           
=========================================
  Files            56       56           
  Lines          2320     2320           
  Branches        369      369           
=========================================
  Hits           2231     2231           
  Misses           48       48           
  Partials         41       41           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1b8dd1f...2edb7af. Read the comment docs.

tntim96 commented 4 years ago

Looks good...minor issue is the comments are re-formatted. Maybe I should put in a shortened or blanket license.