Inspecting generated code
SpecBinder turns each spec file into a Java class at build time. The Test Code pane shows that class beside the spec file.
The Test Code pane
To see the generated class, click the Test Code button in the top-right corner of the
spec file's editor. The class opens in a pane beside the spec file.
The pane opens on the generated *Scenarios class. Tabs along the pane's toolbar list every class
behind the spec: the generated class, the concrete test class, and any base class or interface
that implements one of the spec's steps.
Each tab is a full editor, so the IDE's usual notice — generated files should not be edited — appears above the generated class. A spec file that has never been generated shows No test code found for this spec instead of an empty pane.
Linked ranges
Put the caret on a spec line and the line generated from that spec line is highlighted in the generated class, joined to the spec line by a band across the divider. The pairing runs both ways: a caret on a line of the generated class highlights the spec line behind that Java line.
| In the spec file | Pairs with, in the generated class |
|---|---|
Feature: title | the class declaration |
Rule: title | the @Nested class declaration |
Scenario: or Scenario Outline: title | the test method declaration |
Background: title | the set-up method declaration |
| A step | the call generated for that step — the call in the same scenario, even when the step appears twice |
| A data-table row or doc-string line | the line that builds that row, or the same line of the text block |
An Examples row | the same row of the @CsvSource block |
| A tag | the @Tag annotation |
| A description line | the same Javadoc line, or @Description line |
A comment line pairs with nothing. Edit a scenario, a title or a tag and that line stops pairing until the generated class catches up, so a lit line always means this is what that spec line became, never what an older version became.
Highlight Matching Lines , at the right end of the pane's toolbar, switches the highlight and the
band off and on. The one switch covers every document the pane can show, and the colour lives under
Settings → Tools → SpecBinder → Split view, as Linked-ranges colour.
Staying on the generated class
Follow caret in spec file , beside Highlight Matching Lines, decides whether the pane changes
files as the caret moves. Switched on, a caret on a step opens the class that implements the step —
the concrete test, or a base class or interface — scrolled to the step method. Following is for
reading the step implementations; a step nothing implements, and every line that is not a step,
still opens the generated class.
For reviewing the generated class, switch Follow caret in spec file off and pick the generated class's tab. The pane then holds still: only the tabs change the file on screen, and every step pairs with the call in the generated class instead of sending the pane to the concrete test class. With following off the pane does not scroll by itself either — scroll the generated class to the scenario under review, and the band across the divider shows where each line went.
Navigation
The Test Code pane shows the generated code beside the spec file. To open that code in a full
editor tab instead — with more room to read, or to continue from there into the step methods —
hold Cmd (Ctrl on Windows and Linux) and click a line in the spec file:
Cmd+Click in the spec file | Opens |
|---|---|
Feature: | the generated class |
Rule: | the @Nested class |
Scenario: / Scenario Outline: | the @Test / @ParameterizedTest method |
Background: | the generated @BeforeEach method |
| A step | the step method — the concrete one when implemented, otherwise the abstract declaration |
| A quoted value, doc string or data table | the matching parameter of the step method |
| A tag | the @Tag annotation |
An Examples cell | the @CsvSource annotation |
Cmd+Shift+Click on a step goes to the call in the generated method instead of the step method.
An outline placeholder such as <qty> stays in the spec file and goes to the matching column of the
Examples table.
The way back uses the same gestures: Cmd+Click on the generated class, a @Nested class, a test
method or a @BeforeEach method lands on the Feature:, Rule:, scenario or Background: line,
and Cmd+Shift+Click on a step call lands on the step — the occurrence in that scenario, when the
same step appears in several.