Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring app response test with JUnit Assume #10537

Merged
merged 2 commits into from Sep 3, 2022

Conversation

Codegass
Copy link
Contributor

@Codegass Codegass commented Sep 2, 2022

What is the purpose of the change

FIX #10487

This PR proposes a minor improvement that could apply to two test cases in AppResponseTest(testSetExceptionWithEmptyStackTraceException and testAppResponseWithEmptyStackTraceException). I will use testSetExceptionWithEmptyStackTraceException as an example.

        Throwable throwable = buildEmptyStackTraceException();
        if (throwable == null) {
            return;
        }

On line 68-71, it uses an if condition to check if a precondition is violated, i.e. “buildEmptyStackTraceException fail to construct NPE” If so, the test case return silently without any further execution. There could be two drawbacks to this:

  1. The if and return make the logic of the test case implicit
  2. It may still be worthwhile to execute the test case and see what happens.

The assume function, introduced after JUnit 4&5 is designed to check for test pre-condition. As mentioned in the JUnit 5's document:

Assume functions is a set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information.
The if block could be replaced by After refactoring:

        Throwable throwable = buildEmptyStackTraceException();
        assumeFalse(throwable == null);

This makes the logic more explicit. Although this is a minor change, it can be applied to the two test cases in this AppResponseTest .

Brief changelog

Replace if (throwable == null) {return;} with assumeFalse(throwable == null); for better code comprehension.

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2022

Codecov Report

Merging #10537 (5dfba93) into 3.1 (e5b1caf) will increase coverage by 0.14%.
The diff coverage is 62.12%.

@@             Coverage Diff              @@
##                3.1   #10537      +/-   ##
============================================
+ Coverage     64.60%   64.75%   +0.14%     
- Complexity      373      395      +22     
============================================
  Files          1331     1331              
  Lines         56544    56509      -35     
  Branches       8367     8370       +3     
============================================
+ Hits          36530    36592      +62     
+ Misses        16063    15972      -91     
+ Partials       3951     3945       -6     
Impacted Files Coverage Δ
...rpc/cluster/configurator/AbstractConfigurator.java 61.90% <ø> (+1.58%) ⬆️
...luster/configurator/absent/AbsentConfigurator.java 100.00% <ø> (ø)
...er/configurator/override/OverrideConfigurator.java 100.00% <ø> (ø)
...overnance/DefaultGovernanceRuleRepositoryImpl.java 100.00% <ø> (ø)
...n/java/org/apache/dubbo/common/bytecode/Proxy.java 69.52% <ø> (ø)
...bbo/common/concurrent/CallableSafeInitializer.java 66.66% <0.00%> (ø)
.../org/apache/dubbo/common/config/Configuration.java 78.43% <ø> (ø)
...va/org/apache/dubbo/common/config/Environment.java 81.45% <ø> (ø)
.../apache/dubbo/common/config/ModuleEnvironment.java 47.05% <ø> (-0.24%) ⬇️
.../common/config/OrderedPropertiesConfiguration.java 80.76% <ø> (ø)
... and 50 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@AlbumenJ AlbumenJ merged commit 0b24702 into apache:3.1 Sep 3, 2022
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.

A Minor Improvement to the test cases in AppResponseTest
3 participants