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.
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' |
There was a problem hiding this comment.
For those who come after, GHA added basic yaml anchor support at some point.
|
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
testmod/run configured in loom, since the game will actually have to run to test integration. We might be able to do something with Mojang'sGameTestsystem 🤔. 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
Knotclassloader. 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