Skip to content

AlignBDDStatements

Align BDD statements in the test case body.

Enabling the formatter

AlignBDDStatements is not included in default formatters.

You can enable it by using --select and --extend-select options.

robocop format --select AlignBDDStatements
robocop format --extend-select AlignBDDStatements

Keyword calls prefixed with the BDD reserved keywords (Given, When, And, But and Then) are indented so the keyword names following the prefixes are aligned in a single column:

*** Test Cases ***
There can be only one
    Given there are 3 ninjas
    And there are more than one ninja alive
    When 2 ninjas meet, they will fight
    Then one ninja dies (but not me)
    And there is one ninja less alive
*** Test Cases ***
There can be only one
    Given there are 3 ninjas
      And there are more than one ninja alive
     When 2 ninjas meet, they will fight
     Then one ninja dies (but not me)
      And there is one ninja less alive

The width of the column is calculated separately for every test case using the longest BDD prefix used in its body. Nested blocks (such as IF or FOR) are aligned separately, using their own indentation as a base. Statements that do not start with the BDD prefix, keyword calls with the assignment and keywords from the *** Keywords *** section are not formatted.

BDD prefixes translated to other languages are recognized if the language is configured with the --language option or with the language header.

Indentation

The statement with the longest BDD prefix keeps the normal indentation, and the remaining ones are padded with extra spaces. The indentation can be configured with the global --indent option:

robocop format --select AlignBDDStatements --indent 2
[tool.robocop.format]
select = [
    "AlignBDDStatements"
]
indent = 2
*** Test Cases ***
There can be only one
    Given there are 3 ninjas
    And there are more than one ninja alive
    When 2 ninjas meet, they will fight
*** Test Cases ***
There can be only one
  Given there are 3 ninjas
    And there are more than one ninja alive
   When 2 ninjas meet, they will fight