Class EphemeralTestServerProvider

java.lang.Object
net.neoforged.testframework.junit.EphemeralTestServerProvider
All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver

public class EphemeralTestServerProvider extends Object implements org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.Extension
A ParameterResolver that provides a MinecraftServer parameter.

The server is ephemeral, meaning that it doesn't store any data, and only has a void overworld available.

You should NOT not interact with the world of that server as it purely exists to load datapack data. If you need an actual world, you should use a GameTest instead.

Example usage:

@Test
@ExtendWith(EphemeralTestServerProvider.class)
void someJUnitTest(MinecraftServer server) {
    assert server.registryAccess().registryOrThrow(Registries.ITEM).getTag(ItemTags.ANVIL).isPresent();
}
You can also annotate a class with ExtendWith to provide a server to all tests in that class.

The server instance is lazy (only created if a test needs it) and singleton for the whole JUnit session.

See Also:
  • ExtendWith
  • Field Details

  • Constructor Details

    • EphemeralTestServerProvider

      public EphemeralTestServerProvider()
  • Method Details

    • supportsParameter

      public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
      Specified by:
      supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • resolveParameter

      public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
      Specified by:
      resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • grabServer

      public static MinecraftServer grabServer()