LivingDoc Implementation (Fix for skipped steps and missing error messages) #355
Registeel
started this conversation in
Show and tell
Replies: 1 comment
-
@Registeel Thx for sharing! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have taken an implementation of @dakiers project that generates the TestExecution.json file that is required to run SpecFlow+ LivingDoc with test results. I added everything but the "Hooks" directory to a class library then added the hooks to my existing reqnroll project and it worked great for generating the TestExecution.json file.
There are issues I found that I have resolved in this implementation.
step.TestError?.Message
is always empty so errored steps give no output.I've resolved both of these issues. I'll start with the first problem.
Skipped Steps
The issue with skipped steps is that they are not processed in the
[AfterStep]
hook. So once you hit a failed step, all the skipped ones afterwards are not recorded in theExecutionResult
object that is written to in the[AfterStep]
hook like so:The solution for this problem is to build a custom SkippedStepHandler. This is a custom class with any name you like that inherits the reqnroll
ISkippedStepHandler
interface.My implementation looks like this:
The confusing part about this is where the ExecutionResult is coming from. This is what is used to record the step status to write to the TestExecution.json file. We need to pass this object by reference from the main reqnroll hook file that is running the tests.
I have done this in my
[BeforeScenario]
hook from dakiers project like so:The _objectContainer is an instance of an IObjectContainer that is dependency injected into the main Hook class.
With this setup the _result object is passed to the custom handler and when skipped steps are hit they are written to the result before being written to the TestExecution.json file in the
[AfterScenario]
and[AfterTestRun]
hooks.Onto problem number two.
Empty Error Messages
This one was a simpler problem. Essentially
step.TestError?.Message
is always empty, but you do get an error message for the failure of the step in your Scenario Context.My solution is to change
step.TestError?.Message
, (step
coming fromvar step = scenario.StepContext
), toscenario.TestError?.Message
.If you would like extra logging I also appended
scenario.TestError?.InnerException?.Message
to mine.Beta Was this translation helpful? Give feedback.
All reactions