Skip to content

Conversation

@strangelookingnerd
Copy link
Contributor

@strangelookingnerd strangelookingnerd commented Jan 17, 2024

Background

Thanks to #438 there is now support for JUnit5. However there are still some open points or missing features from JUnit4 evolving around JenkinsRule.

Problem

While trying to upgrade the plugin archetypes to use JUnit5 (jenkinsci/archetypes#691) I encountered one of these open points: Right now there is no implementation that resembles RestartableJenkinsRule or JenkinsSessionRule for JUnit5.

After giving it a try myself to get such an implementation going I quickly found that it will likely require a huge portion of refactoring and changing behavior of JenkinsRule / JUnit5JenkinsRule.

Even though I do think that at some point one might need to bite the bullet and fully re-write most of the implementation for JUnit5 and dropping support for JUnit4 - this is not my decision to make and more importantly I would not want to jump onto that unless that decision is made beforehand 😄

Solution

Anyways, since I still wanted to find some equivalent for RestartableJenkinsRule or JenkinsSessionRule I opted for an extension to JenkinsRule by providing JenkinsRule.restart(). This method basically does the same as the JUnit4 rules but is agnostic to the JUnit version being used.
Summed up shorty it creates a backup of the JENKINS_HOME and restarts the underlying Jenkins instance by running JenkinsRule.after() and JenkinsRule.before() with the backup as home. The port remains unchanged.

From what I can tell this method could be used in favor of RestartableJenkinsRule or JenkinsSessionRule in most of the existing test cases:

This would allow these projects to migrate to JUnit5 eventually without any downside and would open up the way to deprecate / discontinue the usage of JUnit4 in jenkinsci.

@basil: FYI

Testing done

  • Added new tests that demonstrate that JenkinsRule.restart() works for JUnit4 as well as JUnit5.
  • Added additional tests for the resolution of JUnit5JenkinsRule because I found them useful to have.
### Submitter checklist
- [x] Make sure you are opening from a **topic/feature/bugfix branch** (right side) and not your main branch!
- [x] Ensure that the pull request title represents the desired changelog entry
- [x] Please describe what you did
- [ ] Link to relevant issues in GitHub or Jira
- [x] Link to relevant pull requests, esp. upstream and downstream changes
- [x] Ensure you have provided tests - that demonstrates feature works or fixes the issue

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, a few questions

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants