-
-
Notifications
You must be signed in to change notification settings - Fork 46
Re-using steps does not work #361
Comments
@epitka the steps are executed in the correct order. The important thing to consider is that when the scenario method is executed, the steps are not executed. They are collected together and executed after the method has exited. For this reason it is important to never execute any code outside the step expressions. In the code you posted, you are calling Another problem is that you are assigning the I would suggest a different approach: I would aim to move the reusable parts of your testing code into an internal DSL, e.g. [Scenario]
public void Addition(int x, int y, Calculator calculator, int answer)
{
"Given the number 1"
.x(() => x = Numbers.GetOne());
"And the number 2"
.x(() => y = Numbers.GetOne());
"And a calculator"
.x(() => calculator = Calculators.Create());
"When I add the numbers together"
.x(() => answer = Calculators.Add(calculator, x, y));
"Then the answer is 3"
.x(() => Numbers.IsThree(answer));
} Where |
@epitka and btw, thanks for raising this. 👍 |
Thanks for thorough explanation, but then the blog entry should be checked as it specifically states that this would work. Or I am not understanding this code?
|
@epitka you are correct, that code will not work. I guess I must not have tested that code before writing that wiki page, which is rather embarassing. 😒 I'll take down that content and replace it later with something that actually works. Thanks for bringing this to my attention! 👍 |
Actually, in my defense, I think that code may have worked with an earlier version of xbehave (1.x) which IIRC, did execute steps eagerly, as they are defined, rather than collecting them and executing them later. This is actually an interesting consideration. It may be better to investigate reverting back to that style of eager execution. I'll raise a separate issue for that. |
I expected this to work, but it does not as steps do not execute in sequential order. In this case "When" part would be executed first. But wiki page "How can I reuse steps?" suggests that it is approach that would work.
The text was updated successfully, but these errors were encountered: