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

refactor(test): Refactor QueryValidator usage in tests #4091

Conversation

enchobelezirev
Copy link

What this PR changes/adds

  • Fix usages of QueryValidator in tests
  • Extracted the parameterized tests for validating query parameters in a @nested classes inside each test
  • Created a Provider class for providing the subtypes for each Service class when creating the QueryValidator

Why it does that

  • Enhances the tests under control-plane-aggregate-services project

Further notes

*Packages org.eclipse.edc.connector.controlplane.services.contractagreement and their test packages

Linked Issue(s)

Closes #3731

Please be sure to take a look at the contributing guidelines and our etiquette for pull requests.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

We are always happy to welcome new contributors ❤️ To make things easier for everyone, please make sure to follow our contribution guidelines, check if you have already signed the ECA, and relate this pull request to an existing issue or discussion.

@paullatzelsperger
Copy link
Member

@enchobelezirev can you please sign the ECA?

@enchobelezirev enchobelezirev force-pushed the refactor(test)/improve-queryvalidator-testing-strategy branch from 8fda76e to 4bb5da0 Compare April 5, 2024 08:04
@enchobelezirev
Copy link
Author

Hello @paullatzelsperger, I have fixed it :)

@enchobelezirev enchobelezirev changed the title refactor(test): Refactor QueryValidator usage in tests [DRAFT] refactor(test): Refactor QueryValidator usage in tests Apr 5, 2024
@enchobelezirev enchobelezirev marked this pull request as draft April 5, 2024 08:58
@ndr-brt ndr-brt added the refactoring Cleaning up code and dependencies label Apr 5, 2024
@enchobelezirev enchobelezirev marked this pull request as ready for review April 5, 2024 13:17
@enchobelezirev enchobelezirev changed the title [DRAFT] refactor(test): Refactor QueryValidator usage in tests refactor(test): Refactor QueryValidator usage in tests Apr 5, 2024
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

the point in the issue was to avoid this "integration test" thing and test validators and services separately. please provide unit tests for the validators separated from the services ones

@enchobelezirev
Copy link
Author

Hello,

I have seen that there is already defined class for testing the QueryValidator called QueryValidatorTest. I thought that the idea behind the issue was to have main logic of the services tested(including the "search" methods) by working with a mock object of QueryValidator. That is the reason why I have added mock object inside the tests of the services which is just returning the result without executing the actual logic of the QueryValidator.
As for the "integration tests", I thought that testing the logic which is using the QueryValidator is part of the tests of the services and is not needed as a separate tests classes. This is the reason why I have left the "integrationtest" inside each test of the service, as a Nested tests.

Please, correct me if I am wrong or I do not understand something. I am new to the project and there is high chance that I misunderstood the issue.

Thanks!

Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

this is not about the project but to keep a good testing strategy, here we have 2 components tested together in the same integration test for no reason. Dependency injection is used to make classes being testable by their own apart from specific cases, otherwise we'll end up bloated by tons of (harder to maintain) integration tests.

The issue is pretty clear about the desired outcome: "avoid unnecessary integration tests". The validator should be unit tested, since it's dependent from the object type it's validating, there should be a "generic behavior" test (that as you said it already exist, and then some tests for every class that's used (behaviors that currently are verified in the service tests and just need to be moved out somewhere else)

@enchobelezirev
Copy link
Author

@ndr-brt, I will see how to modify the changes so that it complies with the issue.

@enchobelezirev enchobelezirev force-pushed the refactor(test)/improve-queryvalidator-testing-strategy branch from fa04af0 to 098cea1 Compare April 15, 2024 10:44
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.81%. Comparing base (7f20ba5) to head (098cea1).
Report is 219 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4091      +/-   ##
==========================================
+ Coverage   71.74%   74.81%   +3.06%     
==========================================
  Files         919      988      +69     
  Lines       18457    20261    +1804     
  Branches     1037     1139     +102     
==========================================
+ Hits        13242    15158    +1916     
+ Misses       4756     4607     -149     
- Partials      459      496      +37     

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

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

class AssetServiceImplIntegrationTest {
Copy link
Member

@ndr-brt ndr-brt Apr 15, 2024

Choose a reason for hiding this comment

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

As reported in the issue and in my latest 2 comments, please avoid integration tests and transform them in unit tests on the validator.

Copy link

This pull request is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale Open for x days with no activity label Apr 23, 2024
Copy link

github-actions bot commented May 1, 2024

This pull request was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Cleaning up code and dependencies stale Open for x days with no activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor(test): improve QueryValidator testing strategy
4 participants