SpecFlow - Data Driven Testing without Examples



We can perform data driven testing without the help of keyword Examples. This can be done by passing the data directly to the steps within the Feature File enclosed in (''). It will then be provided as an input to the Step Definition File.

Let us verify a module, for which the below steps need to be executed −

  • User launches URL
  • URL should open

Step 1: Create a Feature File

The details of how to create a Feature File is discussed in detail in the Chapter − Feature File.

Feature: Launching application

Scenario: Launch URL
   Given User hits URL 'https://www.tutorialspoint.com/index.htm'
   Then URL should be launched

Step 2: Create a Step Definition File

The details of how to create a Step Definition File is discussed in detail in the Chapter – Step Definition File.

using System;
using TechTalk.SpecFlow;
namespace SpecFlowProject1.Features{
   [Binding]
   public class LaunchingApplicationSteps{
      [Given(@"User hits URL '(.*)'")]
      public void GivenUserHitsURL(string url){
         Console.WriteLine(url);
      }   
      [Then(@"URL should be launched")]
      public void ThenURLShouldBeLaunched(){
         Console.WriteLine("URL should be launched");
      }
   }
}   

Step 3: Execution & Results

Select Launching Application Feature, then click on Run All Tests in View.

Application Feature

Select Launch URL Scenario, then click on Open additional output for this result link.

Application Features

Applications Features

In the above output, the url (https://www.tutorialspoint.com/index.htm) is obtained which is passed directly from the Feature File within the Given step.

Advertisements