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

Use constants for config keys in tests #2070

Merged
merged 2 commits into from
Nov 2, 2019
Merged

Use constants for config keys in tests #2070

merged 2 commits into from
Nov 2, 2019

Conversation

amitd291
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Oct 29, 2019

Codecov Report

Merging #2070 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2070   +/-   ##
=========================================
  Coverage     80.59%   80.59%           
  Complexity     1988     1988           
=========================================
  Files           332      332           
  Lines          5705     5705           
  Branches       1042     1042           
=========================================
  Hits           4598     4598           
  Misses          554      554           
  Partials        553      553
Impacted Files Coverage Δ Complexity Δ
...rbosch/detekt/rules/complexity/NestedBlockDepth.kt 93.47% <0%> (ø) 5% <0%> (ø) ⬇️
...n/kotlin/io/gitlab/arturbosch/detekt/api/Entity.kt 92.3% <0%> (ø) 5% <0%> (ø) ⬇️

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 f5a8086...aa0a0b1. Read the comment docs.

@3flex
Copy link
Member

3flex commented Oct 30, 2019

I understand and appreciate this PR, but I'm against it because changing a constant in a rule can then break user config files since that won't then be detected in the tests. Using literals protects against that (at least for the way most rule tests have been written).

We could use the constants though if there were other tests checking the constant value was as expected, but that also seems a bit wrong, since we should ultimately be testing that the correct config keys affect the behaviour or the rule.

But at the moment I think this PR introduces some risk.

@amitd291
Copy link
Contributor Author

I understand and appreciate this PR, but I'm against it because changing a constant in a rule can then break user config files since that won't then be detected in the tests. Using literals protects against that (at least for the way most rule tests have been written).

We could use the constants though if there were other tests checking the constant value was as expected, but that also seems a bit wrong, since we should ultimately be testing that the correct config keys affect the behaviour or the rule.

But at the moment I think this PR introduces some risk.

Agreed that we generally test using literals ideally. I was aiming towards standardisation, as half of the tests are using constants declared in the rules to test them.

An agreeable approach could probably be introducing the constants within the test file for private access. What do you folks think? @3flex @schalkms @arturbosch

@3flex
Copy link
Member

3flex commented Oct 31, 2019

I think that's a good idea, I'd approve that PR (would need another maintainer to sign off though so maybe wait for another reply). Thanks!

@amitd291
Copy link
Contributor Author

amitd291 commented Oct 31, 2019

I think that's a good idea, I'd approve that PR (would need another maintainer to sign off though so maybe wait for another reply). Thanks!

Okay let's wait for other maintainers' replies and then I can go ahead and do the required changes here. Thanks @3flex

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

I highly appreciate this PR.
It looks good and really improves the code base. However, I'm against introducing a constant in the product just for the unit test. So this 1 constant should be removed. Then we can merge this.

@arturbosch arturbosch added this to the 1.2.0 milestone Nov 2, 2019
@arturbosch arturbosch merged commit 56053ae into detekt:master Nov 2, 2019
smyachenkov pushed a commit to smyachenkov/detekt that referenced this pull request Dec 9, 2019
* Use constants for config keys in tests

* Move constant to test file
smyachenkov pushed a commit to smyachenkov/detekt that referenced this pull request Dec 9, 2019
* Use constants for config keys in tests

* Move constant to test file
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.

6 participants