Class AllureLifecycle
- Manual core — key-addressed methods. Every parent and owner is explicit; they touch no thread state and are safe from any thread. The exceptions are the start/stop transitions of tests and fixtures: starts bind the calling thread (the thread that calls start is by definition the executing thread), and stops unbind or restore only when the calling thread's root is the stopped key.
- Ambient group — keyless overloads that resolve their target from the calling thread's binding.
- Thread group — explicit binding control:
setCurrent(AllureExternalKey),clearCurrent(),bind(AllureExternalKey),bindDetached(AllureExternalKey),bindEmpty(), and the current-key accessors.
Integration adapters model suite-level grouping through flat scopes using
registerScope(AllureExternalKey), addTestToScope(AllureExternalKey, AllureExternalKey), and
writeScope(AllureExternalKey).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new lifecycle with default results writer.AllureLifecycle(AllureResultsWriter writer) Creates a new lifecycle instance with specifiedAllureResultsWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttachment(AllureExternalKey key, String name, String type, InputStream stream, AttachmentOptions options) Adds attachment to a running test, fixture, or step by key.voidaddAttachment(String name, String type, InputStream stream, AttachmentOptions options) Adds attachment to the current test, fixture, or step if one is running.addAttachmentAsync(AllureExternalKey key, String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment to a running test, fixture, or step by key.addAttachmentAsync(String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment to the current test, fixture, or step if one is running.voidaddAttachmentStep(AllureExternalKey parentKey, String name, String type, InputStream content, AttachmentOptions options) Adds an attachment wrapped in its own instant step under the specified parent — the default representation for user-facing attachments.voidaddAttachmentStep(String name, String type, InputStream content, AttachmentOptions options) Adds an attachment wrapped in its own instant step under the current executable — the default representation for user-facing attachments.addAttachmentStepAsync(AllureExternalKey parentKey, String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment wrapped in its own instant step under the specified parent.addAttachmentStepAsync(String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment wrapped in its own instant step under the current executable.voidaddDefaultLabels(AllureExternalKey key, Collection<io.qameta.allure.model.Label> labels) Registers default labels for the test with given key.voidaddTestToScope(AllureExternalKey scopeKey, AllureExternalKey testKey) Adds test to scope.voidaddTestToScope(AllureExternalKey scopeKey, String testUuid) Adds test to scope, referencing the test by its model uuid instead of a runtime key.bind(AllureExternalKey key) Binds the calling thread to the execution stream of the executable identified by the given key, continuing it.Binds a detached child context anchored to the executable identified by the given key, with an empty local stack.Temporarily binds an empty execution context to the calling thread.voidClears the calling thread's binding.Returns the key of the calling thread's current executable — the attach point for new steps and attachments: a test, fixture, or step, if any.Returns the key of the calling thread's root executable — the running test or fixture, if any.voidlogStep(AllureExternalKey parentKey, io.qameta.allure.model.StepResult result) Logs an instant step — started and finished in one call — under the specified parent.voidlogStep(io.qameta.allure.model.StepResult result) Logs an instant step — started and finished in one call — under the current executable.voidRegisters scope.voidscheduleTest(AllureExternalKey key, io.qameta.allure.model.TestResult result) Schedules test with given key.voidscheduleTest(Collection<AllureExternalKey> scopeKeys, AllureExternalKey key, io.qameta.allure.model.TestResult result) Schedules test with given scopes.voidBinds the test or fixture identified by the given key as the calling thread's root, replacing any current binding.voidstartAfterFixture(AllureExternalKey scopeKey, AllureExternalKey fixtureKey, io.qameta.allure.model.FixtureResult result) Starts a new after fixture with given scope and binds it as the calling thread's root, saving the previous binding forstopFixture(AllureExternalKey)to restore.voidstartBeforeFixture(AllureExternalKey scopeKey, AllureExternalKey fixtureKey, io.qameta.allure.model.FixtureResult result) Starts a new before fixture with given scope and binds it as the calling thread's root, saving the previous binding forstopFixture(AllureExternalKey)to restore.voidstartStage(io.qameta.allure.model.StepResult result) Starts a stage — a lightweight phase marker rendered as a regular step.voidstartStep(AllureExternalKey parentKey, AllureExternalKey key, io.qameta.allure.model.StepResult result) Starts a new step as a child of the specified parent.voidstartStep(AllureExternalKey key, io.qameta.allure.model.StepResult result) Starts a new step as a child of the current executable and makes it current on the calling thread, using the given key as the step's identity.voidstartStep(io.qameta.allure.model.StepResult result) Starts a new step as a child of the current executable and makes it current on the calling thread.voidStarts test with given key and binds it as the calling thread's root.voidStops fixture by given key.voidstopStep()Stops the current running step and pops it from the calling thread.voidStops step by given key.voidStops test by given key.voidupdateFixture(AllureExternalKey key, Consumer<io.qameta.allure.model.FixtureResult> update) Updates fixture by given key.voidupdateFixture(Consumer<io.qameta.allure.model.FixtureResult> update) Updates current running fixture.voidupdateStep(AllureExternalKey key, Consumer<io.qameta.allure.model.StepResult> update) Updates step by specified key.voidupdateStep(Consumer<io.qameta.allure.model.StepResult> update) Updates the current running step.voidupdateTest(AllureExternalKey key, Consumer<io.qameta.allure.model.TestResult> update) Updates test by given key.voidupdateTest(Consumer<io.qameta.allure.model.TestResult> update) Updates current running test.voidupdateTestMetadata(Consumer<io.qameta.allure.model.WithMetadata> update) Applies a metadata update to the test-level target of the calling thread's root executable: in a test, the test itself; in a before fixture, the fixture's scope — so the metadata propagates to every test of that scope when it stops.voidwriteGlobals(io.qameta.allure.model.Globals globals) Writes test-run-level attachments and errors immediately.voidWrites scope.voidWrites test by given key.
-
Constructor Details
-
AllureLifecycle
public AllureLifecycle()Creates a new lifecycle with default results writer. Shortcut forAllureLifecycle(AllureResultsWriter) -
AllureLifecycle
Creates a new lifecycle instance with specifiedAllureResultsWriter.- Parameters:
writer- the results writer.
-
-
Method Details
-
writeGlobals
public void writeGlobals(io.qameta.allure.model.Globals globals) Writes test-run-level attachments and errors immediately.- Parameters:
globals- the global attachments and errors
-
registerScope
Registers scope.- Parameters:
key- the external scope key
-
addTestToScope
Adds test to scope. The test is referenced by its runtime key, so it must still be live in storage; the scope's metadata is merged into it when it stops.- Parameters:
scopeKey- the external scope keytestKey- the external test key
-
addTestToScope
Adds test to scope, referencing the test by its model uuid instead of a runtime key. Use for tests that are already written and released from storage — the normal case for a scope that is written after its children, such as an after-method scope or a suite scope closing at run end.- Parameters:
scopeKey- the external scope keytestUuid- the model uuid of the test
-
writeScope
Writes scope.- Parameters:
key- the external scope key
-
scheduleTest
Schedules test with given key.- Parameters:
key- the external test keyresult- the test to schedule
-
scheduleTest
public void scheduleTest(Collection<AllureExternalKey> scopeKeys, AllureExternalKey key, io.qameta.allure.model.TestResult result) Schedules test with given scopes.- Parameters:
scopeKeys- the external scope keyskey- the external test keyresult- the test to schedule
-
startTest
Starts test with given key and binds it as the calling thread's root. The test must be scheduled.- Parameters:
key- the external test key
-
updateTest
Updates test by given key.- Parameters:
key- the external test keyupdate- the update function
-
updateTest
Updates current running test.- Parameters:
update- the update function.
-
addDefaultLabels
public void addDefaultLabels(AllureExternalKey key, Collection<io.qameta.allure.model.Label> labels) Registers default labels for the test with given key. Default labels do not appear on the test result until the test stops:stopTest(AllureExternalKey)merges them after scope metadata, adding, for each distinct label name, the default labels with that name only when the test has no labels with that name by then. Labels provided by the user — through annotations, framework tags, the runtime API, or before fixtures — thus take precedence over defaults instead of being duplicated by them. Repeated calls accumulate.Intended for the framework-computed grouping labels a user may legitimately override: the suite family and BDD structure labels. System labels — framework, language, host, thread, package, testClass, testMethod — are facts about the run, not defaults: set them eagerly on the result (host and thread are overridable only through their dedicated properties, see
ResultsUtils).- Parameters:
key- the external test keylabels- the default labels
-
stopTest
Stops test by given key. The test must be running; scope metadata is merged into the test here, Allure label metadata carried by framework tags is promoted to labels, then default labels are applied for each label name the test still has no labels for. If the test has a test case id but no history id, a compatibility history id is generated from the test case id and the final parameters. A history id supplied by aTestLifecycleListener.beforeTestStop(TestResult)listener is preserved. Unbinds the calling thread only if the test is the calling thread's root.- Parameters:
key- the external test key
-
writeTest
Writes test by given key. Waits for the test's pending async attachments before serializing, so the written result file is a completion marker: everything it references exists.- Parameters:
key- the external test key
-
startBeforeFixture
public void startBeforeFixture(AllureExternalKey scopeKey, AllureExternalKey fixtureKey, io.qameta.allure.model.FixtureResult result) Starts a new before fixture with given scope and binds it as the calling thread's root, saving the previous binding forstopFixture(AllureExternalKey)to restore.- Parameters:
scopeKey- the external scope keyfixtureKey- the external fixture keyresult- the fixture
-
startAfterFixture
public void startAfterFixture(AllureExternalKey scopeKey, AllureExternalKey fixtureKey, io.qameta.allure.model.FixtureResult result) Starts a new after fixture with given scope and binds it as the calling thread's root, saving the previous binding forstopFixture(AllureExternalKey)to restore.- Parameters:
scopeKey- the external scope keyfixtureKey- the external fixture keyresult- the fixture
-
updateFixture
public void updateFixture(AllureExternalKey key, Consumer<io.qameta.allure.model.FixtureResult> update) Updates fixture by given key.- Parameters:
key- the external fixture keyupdate- the update function
-
updateFixture
Updates current running fixture.- Parameters:
update- the update function.
-
stopFixture
Stops fixture by given key. Restores the binding saved at fixture start only if the fixture is the calling thread's root.- Parameters:
key- the external fixture key
-
startStep
public void startStep(io.qameta.allure.model.StepResult result) Starts a new step as a child of the current executable and makes it current on the calling thread. Takes no effect if no executable is running.- Parameters:
result- the step
-
startStep
Starts a new step as a child of the current executable and makes it current on the calling thread, using the given key as the step's identity. The key lets callers address this step later (for example aStepContextthat must target this step even while a nested step is current). Takes no effect if no executable is running.- Parameters:
key- the external step keyresult- the step
-
startStep
public void startStep(AllureExternalKey parentKey, AllureExternalKey key, io.qameta.allure.model.StepResult result) Starts a new step as a child of the specified parent. Pure manual linkage: the step is attached under the parent and no thread state is touched, so this is safe to call from any thread. Stop it withstopStep(AllureExternalKey).- Parameters:
parentKey- the external parent keykey- the external step keyresult- the step
-
startStage
public void startStage(io.qameta.allure.model.StepResult result) Starts a stage — a lightweight phase marker rendered as a regular step. A stage has no explicit stop: it stays open, collecting the steps and attachments that follow, until the next stage starts at the same level or the enclosing step, test, or fixture ends. A stage started inside a step becomes a child of that step. A stage with no status when it closes is marked passed.Stages are an ambient-only concept: their lifetime is defined by the calling thread's binding, so there is no key-addressed form. Takes no effect if no executable is running.
- Parameters:
result- the stage step, carrying its name
-
updateStep
Updates step by specified key.- Parameters:
key- the external step keyupdate- the update function
-
updateStep
Updates the current running step. A stage cannot be updated: stages are addressed by nobody once started, so when the current step is a stage this warns and does nothing — a caller finishing its own step must address it by key.- Parameters:
update- the update function.
-
stopStep
Stops step by given key. Pure manual form with one thread-affine convenience: when the stopped step is bound on the calling thread with open stages above it, those stages are closed first.- Parameters:
key- the external step key
-
stopStep
public void stopStep()Stops the current running step and pops it from the calling thread. Open stages above it are closed first. -
logStep
public void logStep(io.qameta.allure.model.StepResult result) Logs an instant step — started and finished in one call — under the current executable. The step is bound as current for the duration of its listener callbacks, so listeners observe it exactly like a regular step. Takes no effect if no executable is running.- Parameters:
result- the step, carrying its name and status
-
logStep
Logs an instant step — started and finished in one call — under the specified parent. Pure manual linkage: no thread state is touched, so this is safe to call from any thread.- Parameters:
parentKey- the external parent keyresult- the step, carrying its name and status
-
addAttachment
public void addAttachment(AllureExternalKey key, String name, String type, InputStream stream, AttachmentOptions options) Adds attachment to a running test, fixture, or step by key.- Parameters:
key- the external executable keyname- the name of attachmenttype- the content type of attachmentstream- attachment contentoptions- the attachment options
-
addAttachment
Adds attachment to the current test, fixture, or step if one is running.- Parameters:
name- the name of attachmenttype- the content type of attachmentstream- attachment contentoptions- the attachment options
-
addAttachmentAsync
public CompletableFuture<Void> addAttachmentAsync(AllureExternalKey key, String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment to a running test, fixture, or step by key. The attachment content is awaited before the owning test or scope is written.- Parameters:
key- the external executable keyname- the name of attachmenttype- the content type of attachmentbody- the future stream that contains attachment contentoptions- the attachment options- Returns:
- future completed when attachment content is written
-
addAttachmentAsync
public CompletableFuture<Void> addAttachmentAsync(String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment to the current test, fixture, or step if one is running. The attachment content is awaited before the owning test or scope is written.- Parameters:
name- the name of attachmenttype- the content type of attachmentbody- the future stream that contains attachment contentoptions- the attachment options- Returns:
- future completed when attachment content is written
-
addAttachmentStep
public void addAttachmentStep(String name, String type, InputStream content, AttachmentOptions options) Adds an attachment wrapped in its own instant step under the current executable — the default representation for user-facing attachments. Safe to call from listener callbacks: the wrapper step emits no further events. Takes no effect if no executable is running.- Parameters:
name- the name of attachmenttype- the content type of attachmentcontent- attachment contentoptions- the attachment options
-
addAttachmentStep
public void addAttachmentStep(AllureExternalKey parentKey, String name, String type, InputStream content, AttachmentOptions options) Adds an attachment wrapped in its own instant step under the specified parent — the default representation for user-facing attachments. Pure manual linkage: no thread state is touched.- Parameters:
parentKey- the external parent keyname- the name of attachmenttype- the content type of attachmentcontent- attachment contentoptions- the attachment options
-
addAttachmentStepAsync
public CompletableFuture<Void> addAttachmentStepAsync(String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment wrapped in its own instant step under the current executable. The attachment content is awaited before the owning test or scope is written; a failed body marks the step broken before the owner is serialized. Takes no effect if no executable is running.- Parameters:
name- the name of attachmenttype- the content type of attachmentbody- the future stream that contains attachment contentoptions- the attachment options- Returns:
- future completed when attachment content is written
-
addAttachmentStepAsync
public CompletableFuture<Void> addAttachmentStepAsync(AllureExternalKey parentKey, String name, String type, CompletionStage<? extends InputStream> body, AttachmentOptions options) Adds an async attachment wrapped in its own instant step under the specified parent. Pure manual linkage: no thread state is touched. The attachment content is awaited before the owning test or scope is written; a failed body marks the step broken before the owner is serialized.- Parameters:
parentKey- the external parent keyname- the name of attachmenttype- the content type of attachmentbody- the future stream that contains attachment contentoptions- the attachment options- Returns:
- future completed when attachment content is written
-
updateTestMetadata
Applies a metadata update to the test-level target of the calling thread's root executable: in a test, the test itself; in a before fixture, the fixture's scope — so the metadata propagates to every test of that scope when it stops. Metadata written in an after fixture is dropped by design: its tests are already stopped. Takes no effect if no executable is running.- Parameters:
update- the metadata update
-
getCurrentRootKey
Returns the key of the calling thread's root executable — the running test or fixture, if any.- Returns:
- current test or fixture key
-
getCurrentExecutableKey
Returns the key of the calling thread's current executable — the attach point for new steps and attachments: a test, fixture, or step, if any.The returned key is a manual-core identity that can be snapshotted and used later from any thread (capture-now-apply-later).
- Returns:
- current executable key
-
setCurrent
Binds the test or fixture identified by the given key as the calling thread's root, replacing any current binding. Use for callback-spanning context such as a test that is started and finished in separate framework callbacks, possibly on different threads.- Parameters:
key- the external key to make current
-
clearCurrent
public void clearCurrent()Clears the calling thread's binding. -
bind
Binds the calling thread to the execution stream of the executable identified by the given key, continuing it. The returned binding restores the previous context when closed.- Parameters:
key- the external key to bind from- Returns:
- the thread binding
-
bindDetached
Binds a detached child context anchored to the executable identified by the given key, with an empty local stack. Use for independent worker-thread streams under the same executable. The returned binding restores the previous context when closed.- Parameters:
key- the external key to anchor to- Returns:
- the thread binding
-
bindEmpty
Temporarily binds an empty execution context to the calling thread. The returned binding masks any current context until it is closed, then restores the previous context.- Returns:
- the thread binding
-