Class AllureLifecycle

java.lang.Object
io.qameta.allure.AllureLifecycle

public class AllureLifecycle extends Object
The Allure lifecycle: one class, three method groups. The addressing mode of every method is readable from its signature.
  • 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 Details

  • 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

      public void registerScope(AllureExternalKey key)
      Registers scope.
      Parameters:
      key - the external scope key
    • addTestToScope

      public void addTestToScope(AllureExternalKey scopeKey, AllureExternalKey testKey)
      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 key
      testKey - the external test key
    • addTestToScope

      public void addTestToScope(AllureExternalKey scopeKey, String testUuid)
      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 key
      testUuid - the model uuid of the test
    • writeScope

      public void writeScope(AllureExternalKey key)
      Writes scope.
      Parameters:
      key - the external scope key
    • scheduleTest

      public void scheduleTest(AllureExternalKey key, io.qameta.allure.model.TestResult result)
      Schedules test with given key.
      Parameters:
      key - the external test key
      result - 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 keys
      key - the external test key
      result - the test to schedule
    • startTest

      public void startTest(AllureExternalKey key)
      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

      public void updateTest(AllureExternalKey key, Consumer<io.qameta.allure.model.TestResult> update)
      Updates test by given key.
      Parameters:
      key - the external test key
      update - the update function
    • updateTest

      public void updateTest(Consumer<io.qameta.allure.model.TestResult> update)
      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 key
      labels - the default labels
    • stopTest

      public void stopTest(AllureExternalKey key)
      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 a TestLifecycleListener.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

      public void writeTest(AllureExternalKey key)
      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 for stopFixture(AllureExternalKey) to restore.
      Parameters:
      scopeKey - the external scope key
      fixtureKey - the external fixture key
      result - 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 for stopFixture(AllureExternalKey) to restore.
      Parameters:
      scopeKey - the external scope key
      fixtureKey - the external fixture key
      result - 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 key
      update - the update function
    • updateFixture

      public void updateFixture(Consumer<io.qameta.allure.model.FixtureResult> update)
      Updates current running fixture.
      Parameters:
      update - the update function.
    • stopFixture

      public void stopFixture(AllureExternalKey key)
      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

      public void startStep(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. The key lets callers address this step later (for example a StepContext that must target this step even while a nested step is current). Takes no effect if no executable is running.
      Parameters:
      key - the external step key
      result - 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 with stopStep(AllureExternalKey).
      Parameters:
      parentKey - the external parent key
      key - the external step key
      result - 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

      public void updateStep(AllureExternalKey key, Consumer<io.qameta.allure.model.StepResult> update)
      Updates step by specified key.
      Parameters:
      key - the external step key
      update - the update function
    • updateStep

      public void updateStep(Consumer<io.qameta.allure.model.StepResult> update)
      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

      public void stopStep(AllureExternalKey key)
      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

      public void logStep(AllureExternalKey parentKey, io.qameta.allure.model.StepResult result)
      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 key
      result - 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 key
      name - the name of attachment
      type - the content type of attachment
      stream - attachment content
      options - the attachment options
    • addAttachment

      public void addAttachment(String name, String type, InputStream stream, AttachmentOptions options)
      Adds attachment to the current test, fixture, or step if one is running.
      Parameters:
      name - the name of attachment
      type - the content type of attachment
      stream - attachment content
      options - 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 key
      name - the name of attachment
      type - the content type of attachment
      body - the future stream that contains attachment content
      options - 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 attachment
      type - the content type of attachment
      body - the future stream that contains attachment content
      options - 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 attachment
      type - the content type of attachment
      content - attachment content
      options - 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 key
      name - the name of attachment
      type - the content type of attachment
      content - attachment content
      options - 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 attachment
      type - the content type of attachment
      body - the future stream that contains attachment content
      options - 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 key
      name - the name of attachment
      type - the content type of attachment
      body - the future stream that contains attachment content
      options - the attachment options
      Returns:
      future completed when attachment content is written
    • updateTestMetadata

      public void updateTestMetadata(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. 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

      public Optional<AllureExternalKey> 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

      public Optional<AllureExternalKey> 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

      public void setCurrent(AllureExternalKey key)
      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

      public AllureThreadBinding bindDetached(AllureExternalKey key)
      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

      public AllureThreadBinding 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