How to manage global variables in Spec Flow

I have the following test of my controller

[Binding] public class RegisterUserSteps { private AccountController _accountController = new AccountController(); private ActionResult _result; [When(@"the user goes to the register user screen")] public void WhenTheUserGoesToTheRegisterUserScreen() { _result = _accountController.Register(); } [Then(@"the register user view should be displayed")] public void ThenTheRegisterUserViewShouldBeDisplayed() { Assert.AreEqual("Register", _accountController.ViewData["Title"]); } } 

it works fine, but it doesn’t look very good, because I don’t want to create global / class level variables. So there may be an alternative to these variables in the spec stream. Because when we move on to a large application, and a one-step file contains many scripts, then it will be a mess and it will be difficult to manage.

Thank you in advance

+4
source share
1 answer

I try to use ScenarioContext.Current["KeyName"] so that I can define steps in different classes. See Specification Documentation: Sharing Data Between Bindings for more details and some alternatives.

+4
source

Source: https://habr.com/ru/post/1486985/


All Articles