Overview
Run Anvil scenarios through JUnit Jupiter independently of the build tool.
Anvil's JUnit integration selects an environment through @AnvilTest, starts it before each test,
injects ScenarioContext, and closes the environment afterwards. Your test uses ordinary JUnit
Jupiter methods and assertions. This lifecycle belongs to the test framework and does not depend
on Gradle tasks or source-set conventions.
Prepare the test runtime
Add me.whereareiam.anvil:junit at your chosen Anvil version to the dependencies of the tests that
use it. The published artifact brings the Anvil API, JUnit Jupiter, and launcher dependencies.
Supply the selected platform provider and matching agent, a protocol library, and the capabilities
your tests use on the runtime classpath. Keep Anvil artifact versions aligned.
For example, a project that manages its own Gradle test tasks can add the library directly:
dependencies {
testImplementation(platform("me.whereareiam.anvil:bom:0.0.1"))
testImplementation("me.whereareiam.anvil:junit")
// Add the platform providers, protocol library, and capabilities required by your scenarios.
}
tasks.test {
useJUnitPlatform()
}Maven users import the same BOM in dependency management and add the junit artifact with test
scope. No Anvil Gradle or IntelliJ integration is required. Use a JUnit Platform runner with the Jupiter engine. Configure Anvil's
engine properties on the JVM executing those tests, including EULA
acceptance, protocol library selection when needed, and any named artifact paths. The JUnit extension reads
those properties when it starts each scenario.
The Gradle integration prepares these dependencies and settings for its
anvilTest task. Another JUnit launcher must supply the equivalent classpath and properties; it does
not need to invoke an Anvil Gradle task. The embedding guide
explains the runtime components for applications assembling their own classpath.
Select and use a scenario
Follow Scenario selection and context injection to annotate a test method or class. The scenario and its workspace assets declare what starts; JUnit owns when it starts and closes.
Every test gets its own scenario, started before the test and finished after it. All of them come from one engine that lives for the test run, so a process declared with the engine lifetime is started by the first test that needs it and serves the following ones. Tests that JUnit runs in parallel each get their own such processes. A test that needs a stored online account declares it through Accounts.
With a running context, continue to Players and Assertions and waits to exercise the application. Build-specific compilation, test selection commands, and reports belong in the build-tool guide; for Gradle, see Running tests.