Refactor API tests to using JUnit5 + custom extensions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 564
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 29
Description
Overview of the Feature Request
While hacking on code for #8250 I noticed some problems due to how API tests are currently done: creating collections, datasets, users and settings is mostly done within the test code itself.
This request is a request to:
- refactor API tests from JUnit 4 to JUnit 5
- create custom extensions to handle things like database settings, creation of resources
- prepare the test code to be reusable with Testcontainers in #8250
What kind of user is the feature intended for?
(Example users roles: API User, Curator, Depositor, Guest, Superuser, Sysadmin)
- Developer
- (Sysadmin)
What inspired the request?
Some tests failed when working on #8250 because of formerly unexpressed dependencies on setup and settings. As a root cause it became clear that a failing test not resetting a database setting can render other tests to fail.
This can be avoided by creating extensions that hook into the test lifecycles when necessary (@Before/@After is not flexible enough here!) and ensure settings are present (set if not not) and clean up after the test, independent of the outcome. This is MUCH easier with JUnit 5 than 4 (the successor has been designed exactly with this in mind), thus a small refactoring is necessary to move to 5.
The test code would also become much more readable when the repetitive task of creating test users, test collections and test datasets would not have to be repeated code within almost every test routine. Also leaving an inconsistent state when tests fail, as the cleanup is a part of the test.
What existing behavior do you want changed?
- Move all
*IT.javaused in regular integration tests to JUnit5 - Create JUnit 5 extensions for most important tasks (DB settings, resource creation)
- Document this stuff in a dev guide section on how to write API tests
- Update RESTassured from v2.4 to latest v4.4
Any brand new behavior do you want to add to Dataverse?
Not to application behaviour.
Any related open or closed issues to this feature request?
#8250
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the regular integration-test *IT.java files and reviewing their current JUnit 4 setup, RESTassured usage, and lifecycle cleanup. Read the related #8250 context before deciding how the extensions should support reusable resource creation and database settings. Done means the applicable tests use JUnit 5, extensions cover the requested setup and cleanup, RESTassured is updated, and the API-test developer guidance is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, documentation, testing
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100