Skip to content

Fix #1083 NullReferenceException in CucumberMessageFactory.ToTestStep…#1089

Open
clrudolphi wants to merge 4 commits into
mainfrom
fix/rnr1083_retryAbortedScenario
Open

Fix #1083 NullReferenceException in CucumberMessageFactory.ToTestStep…#1089
clrudolphi wants to merge 4 commits into
mainfrom
fix/rnr1083_retryAbortedScenario

Conversation

@clrudolphi

Copy link
Copy Markdown
Contributor

🤔 What's changed?

This is caused when scenario execution stops part-way through the scenario's steps, causing the Formatters' capture of the test case structure to fail. A retry of the scenario would then fail as the code assumed that the first attempt had captured all steps and hooks of the scenario.

Changed the tracking of TestCase components such that it no longer assumes that the first attempt will execute all steps and hooks.

I believe that this issue highlights that 'StopAtFirstError' when False is no longer working correctly. Will track that in a separate Issue.

⚡️ What's your motivation?

#1083
This enhances stability of Formatters when a Retry mechanism is used.

🏷️ What kind of change is this?

  • 🐛 Bug fix (non-breaking change which fixes a defect)

♻️ Anything particular you want feedback on?

📋 Checklist:

  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "[vNext]" section of the CHANGELOG, linking to this pull request & included my GitHub handle to the release contributors list.

This text was originally taken from the template of the Cucumber project, then edited by hand. You can modify the template here.

…Started during scenario cleanup causes scenario to be silently omitted from HTML report.

This is caused when scenario execution stops part-way through the scenario's steps, causing the Formatters' capture of the test case structure to fail. A retry of the scenario would then fail as the code assumed that the first attempt had captured all steps and hooks of the scenario.
@304NotModified

Copy link
Copy Markdown
Member

FYI I like to review this, but I dont think I have enough experience with these code parts. So requested copilot if it has some (small) suggestions

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a NullReferenceException in the Cucumber formatter tracking pipeline when scenarios are retried after an initial (truncated) attempt (e.g., with StopAtFirstError), by making test-case step/hook ledger entries resilient across retries and only publishing the TestCase definition once the ledger is complete.

Changes:

  • Introduces per-attempt occurrence tracking for steps and hooks and uses it to lazily create/reuse ledger entries across retries.
  • Moves TestCase (definition) message publication into PickleExecutionTracker, ensuring it’s published exactly once when the ledger is complete (or at finalization).
  • Updates and adds runtime tests, including a regression test covering “truncated attempt then retry reaches new step”.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Reqnroll/Formatters/ExecutionTracking/TestStepTracker.cs Adds occurrence support and idempotent binding capture for step ledger entries.
Reqnroll/Formatters/ExecutionTracking/StepTrackerBase.cs Extends base tracker identity with an Occurrence index.
Reqnroll/Formatters/ExecutionTracking/StepKind.cs Adds discriminator for occurrence keying (test step vs hook).
Reqnroll/Formatters/ExecutionTracking/TestCaseTracker.cs Replaces “first attempt builds everything” with lazy get-or-create ledger semantics.
Reqnroll/Formatters/ExecutionTracking/TestCaseExecutionTracker.cs Adds per-attempt occurrence counters; removes TestCase publication responsibility.
Reqnroll/Formatters/ExecutionTracking/TestStepExecutionTracker.cs Resolves/creates step ledger entries at StepStarted using occurrence keying.
Reqnroll/Formatters/ExecutionTracking/HookStepExecutionTracker.cs Resolves/creates hook ledger entries using occurrence keying.
Reqnroll/Formatters/ExecutionTracking/HookStepTracker.cs Updates hook tracker to include occurrence identity.
Reqnroll/Formatters/ExecutionTracking/PickleExecutionTracker.cs Publishes TestCase message once when ledger is complete or at finalization.
Reqnroll/Formatters/ExecutionTracking/TestCaseExecutionTrackerFactory.cs Updates factory signature to match new TestCaseExecutionTracker ctor.
Reqnroll/Formatters/ExecutionTracking/ITestCaseExecutionTrackerFactory.cs Updates interface signature accordingly.
Tests/Reqnroll.RuntimeTests/Formatters/ExecutionTracking/TestStepTrackerTests.cs Updates constructor calls to include occurrence parameter.
Tests/Reqnroll.RuntimeTests/Formatters/ExecutionTracking/TestStepExecutionTrackerTests.cs Updates setup to supply IdGenerator and new step tracker ctor signature.
Tests/Reqnroll.RuntimeTests/Formatters/ExecutionTracking/HookStepExecutionTrackerTests.cs Updates hook tracker ctor signature usage.
Tests/Reqnroll.RuntimeTests/Formatters/ExecutionTracking/TestCaseTrackerTests.cs Adds new unit tests for get-or-create ledger behavior across retries/occurrences.
Tests/Reqnroll.RuntimeTests/Formatters/ExecutionTracking/PickleExecutionTrackerTests.cs Adds regression test for truncated attempt followed by retry reaching a new step.
CHANGELOG.md Adds vNext bugfix entry for #1083 (contains a typo to fix).
.gitignore Ignores /.claude directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Reqnroll/Formatters/ExecutionTracking/TestStepTracker.cs
Comment thread Reqnroll/Formatters/ExecutionTracking/TestStepTracker.cs
Comment thread Reqnroll/Formatters/ExecutionTracking/HookStepTracker.cs
Comment thread CHANGELOG.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException in CucumberMessageFactory.ToTestStepStarted during scenario cleanup causes scenario to be silently omitted from HTML report

4 participants