This guide shows you how to implement E2E test for LH.
Run tests:
./gradlew clean test -Dbootstrapper.class=io.littlehorse.e2e.StandaloneBootstrapper
Run LH:
docker compose up -d
Run tests:
./gradlew clean test -Dbootstrapper.class=io.littlehorse.e2e.ExternalLittleHorseBootstrapper
Add the LH dependencies to app/build.gradle
file:
def lhVersion = '0.12.2'
dependencies {
...
implementation "io.littlehorse:littlehorse-client:${lhVersion}"
testImplementation "io.littlehorse:littlehorse-test-utils:${lhVersion}"
testImplementation "io.littlehorse:littlehorse-test-utils-container:${lhVersion}"
...
}
Create a test class:
// Declare this is a E2E test
@LHTest
public class BasicTest {
// Inject the workflow to test
@LHWorkflow(EXAMPLE_BASIC_WF)
private Workflow basicWf;
private WorkflowVerifier verifier;
// Declare the test
@Test
// Run the custom workers
@WithWorkers("myWorker")
public void shouldSayHello() {
// In this test we run a workflow with the input variable: "Anakin Skywalker",
// then it waits for the status COMPLETED, and validates the result output from the worker
verifier.prepareRun(basicWf, Arg.of(INPUT_NAME_VARIABLE, "Anakin Skywalker"))
.waitForStatus(LHStatus.COMPLETED)
.thenVerifyTaskRunResult(0, 1, variableValue -> assertEquals(variableValue.getStr(), "Hello there! Anakin Skywalker"))
.start();
}
// Register a workflow
@LHWorkflow(EXAMPLE_BASIC_WF)
public Workflow registerWf() {
return BasicExample.getWorkflow();
}
// Initialize worker
public Object myWorker() {
return new MyWorker();
}
}
You can define which test bootstrapper to use passing env variables. This is useful when running the test inside a docker container or a pipeline. Example:
BOOTSTRAPPER_CLASS="io.littlehorse.e2e.ExternalLittleHorseBootstrapper" ./gradlew clean test
Add a bootstrapper.class
system property to build.gradle
file:
def bootstrapperClassProperty = 'bootstrapper.class'
test {
useJUnitPlatform()
systemProperty bootstrapperClassProperty, System.getProperty(bootstrapperClassProperty) ?: 'io.littlehorse.e2e.StandaloneBootstrapper'
}
Then you can pass which bootstrapper to use. Example:
./gradlew clean test -Dbootstrapper.class=io.littlehorse.e2e.ExternalLittleHorseBootstrapper
Notice the
-D
.
LH test utils allows you set the default bootstrapper.class
using a property file. This is specially useful when running
the test from an IDE.
Create a test/resources/test.properties
file with:
bootstrapper.class = io.littlehorse.e2e.StandaloneBootstrapper