Unused Step Definitions

Use the CLI tool to generate LivingDoc report which also includes Unused step Definition report under the analytics tab. Scope handling included.

You can use this report to find unused code in the automation layer, as it will list the unused bindings from your test assembly/binding assemblies.

Steps appearing under the Unused Step Definitions section are steps that exist in the automation layer but are not used in any feature files.

Usage

Add the optional --binding-assemblies option to the command line tool to specify the assemblies you want to scan. Glob patters are supported e.g.: MyProject/**/MyBindings.dll.

If you have both the feature files and step definitions in the same test assembly, you don’t have to explicitly specify the --binding-assemblies option. See an example below.

If a Step Definition appears under the Unused Step Definitions, you should check if all of the Step Definition Attributes are used. Any unused Step Definition Attribute will be reported as Unused Step Definition. Example:

Feature: Calculator

Scenario: Add two numbers
    Given the first number is 50
    And the second number is 70
    When the two numbers are added
    Then the result should be 120
[When("the two numbers are added")]
[When("we sum the two numbers")]
public void WhenTheTwoNumbersAreAdded()
{
    // ...
}

The Step Definition Attribute with Regex we sum the two numbers will be reported as Unused Step Definition, because it is not used in any of the Feature files.

Viewing Unused Step Definition Report

You can find it on the Analytics tab of the Living Documentation under the Unused Step Definitions section.

  • No data found for the report

No data found for the report

  • No unused step definitions - All step definitions are used

No unused step definitions - All step definitions are used

  • Some step definitions are not used

Some step definitions are not used

Examples

feature-folder command

  • Collect Unused Step Definitions from a binding assembly using feature-folder command:

    livingdoc feature-folder C:/Work/MyProject/Features --binding-assemblies "C:/Work/MyProject/bin/Debug/MyBindings.dll"
    
  • Collect Unused Step Definitions from multiple binding assemblies using feature-folder command:

    livingdoc feature-folder C:/Work/MyProject/Features --binding-assemblies "C:/Work/MyProject/bin/Debug/MyBindings.dll" "C:/Work/MyProject/bin/Debug/MyStepDefinitions.dll"
    

feature-data command

  • Collect Unused Step Definitions from a binding assembly using feature-data command:

    livingdoc feature-data C:/Work/FeatureData.json --binding-assemblies "C:/Work/MyProject/bin/Debug/MyBindings.dll"
    
  • Collect Unused Step Definitions from multiple binding assemblies using feature-data command:

    livingdoc feature-data C:/Work/FeatureData.json --binding-assemblies "C:/Work/MyProject/bin/Debug/MyBindings.dll" "C:/Work/MyProject/bin/Debug/MyStepDefinitions.dll"
    

test-assembly command

  • Collect Unused Step Definitions from the test assembly using the test-assembly command:

    livingdoc test-assembly C:/Work/MyProject/MyAssembly.dll
    

    In this case the MyAssembly.dll will be scanned automatically to find Unused Step Definitions. In other words, you don’t need to specify --binding-assemblies "C:/Work/MyProject/MyAssembly.dll" explicitly.

  • Collect Unused Step Definitions from the test assembly and from a binding assembly using the test-assembly command:

    livingdoc test-assembly C:/Work/MyProject/MyAssembly.dll --binding-assemblies "C:/Work/MyProject/bin/Debug/MyBindings.dll"
    
  • Collect Unused Step Definitions from the test assembly and from binding assemblies using the test-assembly command:

    livingdoc test-assembly C:/Work/MyProject/MyAssembly.dll --binding-assemblies "C:/Work/MyProject/bin/Debug/MyBindings.dll" "C:/Work/MyProject/bin/Debug/MyStepDefinitions.dll"
    

    In this case 3 assemblies will be scanned:

    • MyAssembly.dll
    • MyBindings.dll
    • MyStepDefinitions.dll

Limitations

Currently only Regular expressions in attributes is supported. Learn more about Step Matching Styles.