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
You can also annotate a class with
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();
}
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:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final AtomicBoolean
static final AtomicReference
<MinecraftServer> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic MinecraftServer
resolveParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) boolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
Field Details
-
SERVER
-
IN_CONSTRUCTION
-
-
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 interfaceorg.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 interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
grabServer
-