user1512585
user1512585

Reputation: 41

SpecFlow Dependent Features

I have 2 Features 1. User Creation 2. User Enrollment both are separate and have multiple scenarios. 2nd Feature is dependent on 1st one, so when I run the 2nd Feature directly then how this feature checks the 1st Feature is already run and user created. I am using database in which creation status column (True/False) tells if user has been created or not. So, I want if i run the 2nd feature before that it runs the 1st feature for user creation.

Upvotes: 0

Views: 1602

Answers (2)

Andulanus
Andulanus

Reputation: 21

I used reflection

  1. Find all Types with a DescriptionAttribute (aka Features)
  2. Find their MethodInfos with a TestAttribute and DescriptionAttribute (aka Scenarios)
  3. Store them to a Dictionary
  4. Call them by "Title of the Feature/Title of the Scenario" with Activator.CreateInstance and Invoke

You have to set the (private) field "testRunner" according to your needs of course.

Upvotes: 0

Void Ray
Void Ray

Reputation: 10209

In general, it is considered a very bad practice to have dependencies between tests and a specially features. Each test/scenario should have its own independent setup.

If your second feature depends on user creation, you could just add another step to you scenarios, e.g. "When such and such user is created."

If all scenarios under one feature share common content, you could move it up under a Background tag. For example:

Feature: User Enrollment

Background Given such and such user

Scenario When ... And ... Then...

Scenario When ... And ... Then...

Upvotes: 1

Related Questions