# Unused Step Definitions Use [the CLI tool](Using-the-command-line-tool.md) to generate LivingDoc report which also includes Unused step Definition report under the analytics tab. [Scope](https://docs.specflow.org/projects/specflow/en/latest/Bindings/Scoped-Step-Definitions.html) 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](Using-the-command-line-tool.md) 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](#test-assembly-command) below. If a Step Definition appears under the Unused Step Definitions, you should check if all of the [Step Definition Attributes](https://docs.specflow.org/projects/specflow/en/latest/Bindings/Step-Definitions.html#supported-step-definition-attributes) are used. Any unused Step Definition Attribute will be reported as Unused Step Definition. Example: ```gherkin 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 ``` ```c# [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](../_static/images/unusedsteps_no_data.png) - No unused step definitions - All step definitions are used ![No unused step definitions - All step definitions are used](../_static/images/unusedsteps_all_steps_used.png) - Some step definitions are not used ![Some step definitions are not used](../_static/images/unusedsteps.png) ## 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](https://docs.specflow.org/projects/specflow/en/latest/Bindings/Step-Definitions.html#regular-expressions-in-attributes) is supported. Learn more about [Step Matching Styles](https://docs.specflow.org/projects/specflow/en/latest/Bindings/Step-Definitions.html#step-matching-styles-rules).