Creating HTML report for test execution result

How to create HTML report with details of test execution Very often , we will be required to create a report with details of test execution , so that it can be presented to various stakeholders. Specflow provides a feature to create HTML reports. Let us look into more details about how is this done Read through and understand details of reporting from specflow. Ensure packages for Specflow, Nunit, Nunit console runner are already installed. If you are using Nunit 3, install NUnit.Extension.NUnitV2ResultWriter package via nuget package manager. If this is not installed, we will get an error “Unknown result format: nunit2”. Follow setups required for running specflow test cases from command line. Details can be found here. Modify the bat file to create nunit2 reports. PathToNunitConsolerunner\nunit3-console.exe --labels=All --out=TestResult.txt "--result=TestResult.xml;format=nunit2" PathTo\AcceptanceTests.dll Add below command into Bat file. This will create HTML Report called “MyResult.html” PathToSpecfloPackage\specflow.exe nunitexecutionreport PathTo\AcceptanceTests.csproj /out:MyResult.html Final bat file will look like below. REM bat file to run test cases from console and create xml result file .\..\..\..\packages\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe --labels=All --out=TestResult.txt "--result=TestResult.xml;format=nunit2" .\AcceptanceTest.dll REM Generate html report from test output .\..\..\..\packages\SpecFlow.2.1.0\tools\specflow.exe nunitexecutionreport .\..\..\AcceptanceTest.csproj /out:MyResult.html EDITED: If it throws below error in newer version of Visual Studio then ensure MS Build tool 2013 is installed. It can be downloaded from https://www.microsoft.com/en-US/download/details.aspx?id=40760 ...

March 5, 2017

Running Specflow Test from command line using Nunit

How to run specflow test cases from command line We can use nunit console runner for running specflow test cases from command line. Running specflow test cases through nunit console runner will help to create test results in xml file, which can then be used for creating html reports. Procedure for command line test execution are Define Nunit as the test runner. This is done in config file <specFlow> <unitTestProvider name="NUnit"/> </specFlow> Include Nunit.Console.Runner package to solution via nuget package manager Run specflow test cases using below command. We can create a bat file with below command and execute them as required. pathToNunitConsoleRunner\nunit3-console.exe PathToProject.dll example will be .\..\..\..\packages\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe .\BDDFramework.dll

March 4, 2017

Nunit Assert

Assert.AreEqual vs Assert.AreSame Very frequently I use Assert.AreEqual and Assert.AreSame for doing assertions in the code. Below is high level difference between both. Assert.AreSame Assert.AreSame checks whether both comparing objects are exactly the same ( reference indicate same object in memory) .It is normally known as Reference Equality Assert.AreEqual Assert.AreEqual checks whether both objects contain same value. It is normally known as Value Equality. For primitive value types ( like int, bool) this is straight forward. But for other types ( especially user defined objects) , it is depends on how the type defines equality. ...

August 22, 2016