Skip to content

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

Open
eas5 wants to merge 1 commit into
tntim96:masterfrom
eas5:test_improvement
Open

Test improvement: removed Exception Handling (test smell)#292
eas5 wants to merge 1 commit into
tntim96:masterfrom
eas5:test_improvement

Conversation

@eas5
Copy link
Copy Markdown

@eas5 eas5 commented Jul 29, 2020

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown
Owner

tntim96 commented Jul 29, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants