Skip to content

<test>(sdk): raise unit-test coverage 54.6% -> 69.9% (pure-Java, no node)#959

Merged
kyonRay merged 3 commits into
FISCO-BCOS:release-3.9.0from
kyonRay:test/raise-unit-coverage
Jul 7, 2026
Merged

<test>(sdk): raise unit-test coverage 54.6% -> 69.9% (pure-Java, no node)#959
kyonRay merged 3 commits into
FISCO-BCOS:release-3.9.0from
kyonRay:test/raise-unit-coverage

Conversation

@kyonRay

@kyonRay kyonRay commented Jun 23, 2026

Copy link
Copy Markdown
Member

What

Adds offline (no live node) JUnit4 unit tests that substantially raise the unit-test coverage tracked by Codecov.

Unit-only JaCoCo (the CI/Codecov-visible metric — .codecov.yml ignores the integration-test dirs):

metric before after
instruction 54.57% 69.87%
line 56.24% 68.22%
branch 67.79%
method 76.07%

26 new test files, all passing offline under Java 8. No production code is modified.

How

The biggest "uncovered" chunks were the generated precompiled and auth contract wrappers and their high-level *Service classes — which looked integration-only but are actually pure-Java once instantiated. The tests:

  • instantiate wrappers/services with a mocked Client (Mockito) + a real new CryptoSuite(CryptoType.ECDSA_TYPE) keypair — no BcosSDK.build / Client.build / network;
  • drive the getXxxInput/getXxxOutput decoders via ABI round-trips (encode known args with the SDK's own FunctionEncoder, set them on a TransactionReceipt, decode, assert);
  • drive read paths by stubbing client.call(...) with ABI-encoded outputs;
  • cover pure-Java codec/model/util classes (ContractLoader, ContractCodec, AbiTypes, ABIDefinition, TransactionReceipt, JsonTransactionResponse, StringUtils, CryptoSuite, …) directly.

Notable package gains

contract/auth/contracts 6.7% → 88.2%, precompiled/crud 6.8% → 67%, precompiled/consensus 12.5% → 66%, precompiled/balance 20% → 72%, precompiled/bfs 36% → 74%, transaction/tools 36% → 89%, utils → 95%, model → 93%.

Scope / what is intentionally not covered

The remaining gap is genuinely node/JNI-dependent and not unit-testable: ClientImpl JSON-RPC, live transaction submission (native TransactionBuilderJniObj signing), and the eventsub/filter push loops. Those are exercised by the integrationTest suite instead.

🤖 Generated with Claude Code

… 69.9%

Adds offline (no live node) JUnit4 unit tests that drive the generated
precompiled and auth contract wrappers, their high-level Service classes, and
several pure-Java codec/model/util classes. The wrappers are exercised via a
mocked Client (Mockito) plus ABI round-trips (encode known args with the SDK's
own FunctionEncoder, feed to the getXxxInput/getXxxOutput decoders) and stubbed
client.call(...) outputs, so no chain or JNI transaction signing is required.

Unit-only JaCoCo (verifiable in CI/Codecov, which ignores integration-test
dirs): instruction 54.57% -> 69.87%, line 56.24% -> 68.22%, branch -> 67.79%,
method -> 76.07%. Notable package gains: contract/auth/contracts 6.7% -> 88.2%,
precompiled/crud 6.8% -> 67%, consensus 12.5% -> 66%, balance 20% -> 72%,
bfs 36% -> 74%, transaction/tools 36% -> 89%.

Test-only change; no production code modified.
Copilot AI review requested due to automatic review settings June 23, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.05%. Comparing base (a91d7e5) to head (69b9073).

Additional details and impacted files
@@                 Coverage Diff                  @@
##             release-3.9.0     #959       +/-   ##
====================================================
+ Coverage            52.20%   64.05%   +11.84%     
- Complexity            4056     4566      +510     
====================================================
  Files                  430      430               
  Lines                17628    17628               
  Branches              1969     1969               
====================================================
+ Hits                  9203    11291     +2088     
+ Misses                7684     5576     -2108     
- Partials               741      761       +20     
Flag Coverage Δ
unittest 64.05% <ø> (+11.84%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

@kyonRay kyonRay merged commit ab0390c into FISCO-BCOS:release-3.9.0 Jul 7, 2026
6 of 7 checks passed
@kyonRay kyonRay deleted the test/raise-unit-coverage branch July 7, 2026 09:51
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