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

Fix tests not reverting system property and environment variable changes #578

Conversation

Marcono1234
Copy link
Contributor

@Marcono1234 Marcono1234 commented Jan 10, 2022

Some of the tests related to the system property and environment variable extension were changing system properties and environment variables manually, but were not reverting the changes afterwards.

I have only added the necessary calls to remove the custom entries. A more extensive solution would be to store the existing value (if any) in a field and restore that value afterwards. However, because custom system property and environment variable names are used, there are most likely no existing old values, so that extra logic would probably be redundant.

Also, should these test classes be annotated with @WritesSystemProperty and @WritesEnvironmentVariable, or was that intentionally not done to prevent spurious test success in case these annotations behave incorrectly?
(And do the tests currently rely on the fact that the used system property and environment variable names are unique per test?)

Proposed commit message:

Fix tests not reverting system property and env variable changes (#578)

PR: #578

PR checklist

The following checklist shall help the PR's author, the reviewers and maintainers to ensure the quality of this project.
It is based on our contributors guidelines, especially the "writing code" section.
It shall help to check for completion of the listed points.
If a point does not apply to the given PR's changes, the corresponding entry can be simply marked as done.

Documentation (general)

  • There is documentation (Javadoc and site documentation; added or updated)
  • There is implementation information to describe why a non-obvious source code / solution got implemented
  • Site documentation has its own .adoc file in the docs folder, e.g. docs/report-entries.adoc
  • Only one sentence per line (especially in .adoc files)
  • Javadoc uses formal style, while sites documentation may use informal style

Documentation (new extension)

  • The docs/docs-nav.yml navigation has an entry for the new extension
  • The package-info.java contains information about the new extension

Code

  • Code adheres to code style, naming conventions etc.
  • Successful tests cover all changes
  • There are checks which validate correct / false usage / configuration of a functionality and there are tests to verify those checks
  • Tests use AssertJ or our own PioneerAssert (which are based on AssertJ)

Contributing

  • A prepared commit message exists
  • The list of contributions inside README.md mentions the new contribution (real name optional)

I hereby agree to the terms of the JUnit Pioneer Contributor License Agreement.

Copy link
Member

@Michael1993 Michael1993 left a comment

Choose a reason for hiding this comment

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

Hm, I don't think this is necessary. AbstractEntryBasedExtension already implements AfterEachCallback and AfterAllCallback with resetting behaviour.

@Marcono1234
Copy link
Contributor Author

AbstractEntryBasedExtension already implements AfterEachCallback and AfterAllCallback with resetting behaviour

But that is only used when you actually use the extension (e.g. through @SetSystemProperty). The changes done by this PR are for unit tests which explicitly set system properties and environment variables using System.setProperty and EnvironmentVariableUtils.set. And therefore, if I understand it correctly, they will by default not be cleaned up again and be visible to other unrelated tests.

@nipafx
Copy link
Member

nipafx commented Feb 19, 2022

@Marcono1234 I just noticed that you're not mentioned in the README under Contributors. We'll gladly have you there! If you're ok with that, feel free to add your various contributions in this PR.

@Marcono1234
Copy link
Contributor Author

Unless you really want me to be listed there, I don't mind not being listed there for my previous contributions.

@nipafx
Copy link
Member

nipafx commented Mar 10, 2022

It's totally up to you. Just know that you can add yourself in any PR if you want to.

@nipafx nipafx added the full-build Triggers full build suite on PR label Mar 10, 2022
@nipafx nipafx dismissed beatngu13’s stale review March 10, 2022 21:01

The requested changes were made.

@nipafx nipafx merged commit 09f08be into junit-pioneer:main Mar 10, 2022
@Marcono1234 Marcono1234 deleted the tests-not-reverting-system-property-env-var-changes branch March 10, 2022 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full-build Triggers full build suite on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants