Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

In this tutorial, we will create a simple Specflow test in C#, using Nunit NUnit as the test runner.

 


Info
titleNotes

Although this tutorial explores a way of managing Specflow tests " in JIRA"Jira, it does no not take advantage of Xray's Cucumber features.

Therefore, in this case, JIRA Jira isn't used to make the BDD specification; only to abstract the Tests. Tests The tests in JIRA Jira wil be created as Generic Tests and , not Cucumber Tests. This is, since the semantic Since the semantics of Cucumber tests Tests is lost, such are also, for example,  so do the Scenario Outline examples-related results.

...


Description

Specflow is a tool used for BDD in C#.

In this case, we'll start by writing The example, the test case validates a Calculator class and exploits some Nunit NUnit features, such as the ability of validating to validate the same Test against multiple input values, and also the possibility of linking Tests with requirements in JIRA through the usage of Nunit's Jira by using Test attributes. 


Code Block
titleCalculator.feature
Feature: Calculator
       In order to avoid silly mistakes
       As a math idiot
       I want to be told the arithmetic operation of two numbers
@mytag
Scenario: Add two numbers
       Given I have entered 50 into the calculator
       And I have also entered 70 into the calculator
       When I press add
       Then the result should be 120 on the screen

Scenario: Multiply two numbers
       Given I have entered 2 into the calculator
       And I have also entered 3 into the calculator
       When I press multiply
       Then the result should be 6 on the screen

Scenario Outline: Amazing addition of  two numbers
       Given I have entered <input_1> into the calculator
       And I have also entered <input_2> into the calculator
       When I press add
       Then the result should be <output> on the screen
		  Examples:
		    | input_1 | input_2 | output |
		    | 20      | 30      | 50     |
		    | 30      | 50      | 80     |

...

Code Block
titlepackages.config
collapsetrue
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="NUnit" version="3.6.0" targetFramework="net452" />
  <package id="NUnit.Console" version="3.6.0" targetFramework="net452" />
  <package id="NUnit.ConsoleRunner" version="3.6.0" targetFramework="net452" />
  <package id="NUnit.Extension.NUnitProjectLoader" version="3.5.0" targetFramework="net452" />
  <package id="NUnit.Extension.NUnitV2Driver" version="3.6.0" targetFramework="net452" />
  <package id="NUnit.Extension.NUnitV2ResultWriter" version="3.5.0" targetFramework="net452" />
  <package id="NUnit.Extension.TeamCityEventListener" version="1.0.2" targetFramework="net452" />
  <package id="NUnit.Extension.VSProjectLoader" version="3.5.0" targetFramework="net452" />
  <package id="NUnit3TestAdapter" version="3.6.0" targetFramework="net452" />
  <package id="Shouldly" version="2.8.2" targetFramework="net452" />
  <package id="SpecFlow" version="2.1.0" targetFramework="net452" />
  <package id="SpecFlow.NUnit" version="2.1.0" targetFramework="net452" />
</packages>

 


After successfully running successfuly the Scenarios and generating the NUnit XML report (e.g. , TestResult.xml), it can be imported to Xray (either by via the REST API or through "the Import Execution Results" action within the Test Execution).

 


No Format
nunit3-console bin\Debug\UnitTestProject2.dll
No Format
curl -H "Content-Type: multipart/form-data" -u admin:admin -F "file=@TestResult.xml" "http://localhost:8080/rest/raven/1.0/import/execution/nunit?projectKey=CALC"

...


NunitNUnit's Test Case is mapped to a Generic Test in JIRAJira, and the "Generic Test Definition" field contains the name of the class, and the method name that implements the Test Case.

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the Test Case class.

 


 

 



References

 

...