-
Notifications
You must be signed in to change notification settings - Fork 28
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
Initial unit tests #153
base: main
Are you sure you want to change the base?
Initial unit tests #153
Conversation
Pinging @shartte, the original author of |
a26b8df
to
bc81682
Compare
You can |
dda0856
to
38f1871
Compare
Since 1.17, Minecraft checks whether `Bootstrap` has been called, when any of its registries static constructor runs. This means we have to explicitly bootstrap test cases that use any of the registries. Added an annotation `@BootstrapMinecraft` to support this.
(cherry picked from commit 05b9860)
5a43894
to
e6fa497
Compare
- '1.18' | ||
- '1.19' | ||
pull_request: | ||
branches: *branches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow is not valid. .github/workflows/main.yml:
Anchors are not currently supported. Remove the anchor 'branches'
I guess GitHub doesn't like yaml anchors...
branches: *branches | |
branches: | |
- 'main' | |
- '1.16' | |
- '1.17' | |
- '1.18' | |
- '1.19' |
Putting this comment from the Architectury discord here for my own reference...
|
Looks like neoforged/FancyModLoader#54 will provide a Neoforge equivalent of |
Beginning work on unit tests, opening a draft PR for early feedback.
The key breakthrough was calling
Bootstrap.bootStrap()
before running tests; without bootstrapping minecraft, registries (etc) are not initialized and essentially no MC classes can be constructed. This apparently affects 1.17 & newer.My solution is based on this GPL3 code, see comments below.
The goal of this PR is not to provide full test coverage, nor is this PR attempting to add integration tests with minecraft dependencies. That can all come in the future.
Instead this PR aims to enable basic unit testing functionality and provide one or two examples as a starting point.
Integration tests will likely require a
test
mod/run configured in loom, since the game will actually have to run to test integration. We might be able to do something with Mojang'sGameTest
system 🤔. That's all out of scope for this PR though.JUnit 5 is chosen as the testing toolkit to run the tests. Upstream docs.
Mockito is chosen as a mocking framework to mock class dependencies. Upstream docs.
fabric-loader-junit tells JUnit to use fabric's
Knot
classloader. This enables things like mixin & Environment stripping.See also
Writing good tests, in particular: don't mock a type you don't own; a long term goal should be to reduce hard dependencies on mc classes & also write integration tests.
AssertJ (alternative assertions syntax we could use instead).
Fixes #151