FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Removed exception handling (test smell) by eas5 · Pull Request #567 · prometheus/client_java · GitHub

Removed exception handling (test smell) - #567

Merged
brian-brazil merged 1 commit into
prometheus:masterfrom
eas5:test_improvement
Aug 13, 2020
Merged

Removed exception handling (test smell)#567
brian-brazil merged 1 commit into
prometheus:masterfrom
eas5:test_improvement

Conversation

eas5 commented Aug 13, 2020

Copy link
Copy Markdown
Contributor

This is a test refactoring.

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

Solution:
The use of JUnit's exception handling to automatically pass/fail the test instead of writing custom exception handling code or throwing an exception is encouraged.

Result:
Before:

  @Test
  public void testUnbound() throws IOException {
    CollectorRegistry registry = new CollectorRegistry();
    try {
      HTTPServer s = new HTTPServer(HttpServer.create(), registry, true);
      s.stop();
      fail("Should refuse to use an unbound HttpServer");
    } catch (IllegalArgumentException expected) {
    }
  }

After:

  @Test(expected = IllegalArgumentException.class)
  public void testRefuseUsingUnbound() throws IOException {
    CollectorRegistry registry = new CollectorRegistry();
    HTTPServer s = new HTTPServer(HttpServer.create(), registry, true);
    s.stop();
  }

Copy link
Copy Markdown
Contributor

Can you add the DCO?

Signed-off-by: Elvys Soares <eas5@cin.ufpe.br>
eas5 force-pushed the test_improvement branch from 3b6ec5f to cfe595d Compare August 13, 2020 14:59

eas5 commented Aug 13, 2020

Copy link
Copy Markdown
Contributor Author

@brian-brazil Sure! Done!

brian-brazil merged commit c41bef4 into prometheus:master Aug 13, 2020

Copy link
Copy Markdown
Contributor

Thanks!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL