Skip to content

Testing Java Extensions ​

MBD2 21.1.1

Test a capability and trait together. A codec-only test cannot detect duplication, simulation mutation, wrong IO direction, or a handler that is never discovered by recipe logic.

Minimum test matrix ​

AreaRequired cases
RegistrationRegistry contains the exact stable name; optional modID guard behaves correctly
SerializationDefinition, condition, and content codec round-trip without losing fields
Trait persistenceStored value survives block-entity save/load and clamps invalid values
Simulationsimulate=true returns the correct remainder and changes no state
Commitsimulate=false changes state once and returns the same remainder as simulation predicted
IOIN consumes machine storage; OUT fills it; incompatible handler IO returns content unchanged
Slot routingNamed content reaches only handlers advertising that slot name
Multiple handlersRemainder passes to the next handler; isDistinct produces the intended behavior
UI/XEITemplate binds without class casts or missing IDs; per-tick and chance annotations display
LifecycleCaches/listeners are released on unload and removal

Direct handler test pattern ​

java
var trait = getHeatTrait(machine);
trait.setStored(500);
var handler = trait.getRecipeHandlerTraits().getFirst();

var simulatedLeft = handler.handleRecipe(
    IO.IN, recipe, List.of(400), null, true);
assertNull(simulatedLeft);
assertEquals(500, trait.getStored());

var committedLeft = handler.handleRecipe(
    IO.IN, recipe, List.of(400), null, false);
assertNull(committedLeft);
assertEquals(100, trait.getStored());

Also test partial handling: request 700 from a store of 500, expect [200] and a final store of zero on commit.

Game tests ​

Use NeoForge game tests for block capability exposure, multiblock proxying, automatic IO, world-dependent conditions, and full recipe-logic transitions. Soft-dependency test classes must only be loaded inside ModList.isLoaded(...) guards; annotation discovery can otherwise load absent-mod classes eagerly.

Released under the MIT License.