Debian Codegraph @

features/exploratory_testing.with_table.feature

raw
1 Feature: Exploratory Testing with Tables and Table Annotations
2
3 As a tester
4 I want sometimes to explore a problem domain
5 And see not only the expected results
6 But also the actual results in a table.
7
8 . HINT: Does not work with monochrome format in pretty formatter:
9 . behave -f pretty --no-color ...
10 . behave -c ...
11
12
13 @setup
14 Scenario: Feature Setup
15 Given a new working directory
16 And a file named "features/steps/explore_with_table_steps.py" with:
17 """
18 from behave import given, when, then, step
19
20 database = {
21 "Alice": { "age": 10 },
22 "Bob": { "age": 11 },
23 }
24
25 @when('I query the database with')
26 def step_query_database_and_update_table(context):
27 assert context.table, "REQUIRE: table"
28 context.table.require_column("Name")
29 age_index = context.table.ensure_column_exists("Age")
30 for index, row in enumerate(context.table.rows):
31 name = row["Name"]
32 person = database.get(name, None)
33 if person:
34 row.cells[age_index] = str(person["age"])
35 context.current_table = context.table
36
37 @when('I add {number:n} to column "{column}"')
38 def step_query_and_annotate_database(context, number, column):
39 assert context.current_table, "REQUIRE: current_table"
40 age_index = context.current_table.ensure_column_exists("Age")
41 for row in context.current_table.rows:
42 value = int(row.cells[age_index]) or 0
43 row.cells[age_index] = str(value + number)
44
45 @step('note that the "{name}" column was added to the table')
46 def step_note_that_column_was_added(context, name):
47 assert context.current_table.has_column(name)
48
49 @then('note that the "{name}" column was modified in the table')
50 def step_note_that_column_was_modified(context, name):
51 pass
52
53 @then('I inspect the table')
54 def step_inspect_table(context):
55 assert context.current_table
56 context.table = context.current_table
57
58 @then('the table contains')
59 def step_inspect_table(context):
60 assert context.table, "REQUIRE: table"
61 assert context.current_table, "REQUIRE: current_table"
62 assert context.table == context.current_table
63 """
64
65
66 Scenario: Add table column with new data in a step and ensure changes are shown
67 Given a file named "features/table.set_column_data.feature" with:
68 """
69 Feature:
70 Scenario:
71 When I query the database with:
72 | Name |
73 | Alice |
74 | Bob |
75 Then note that the "Age" column was added to the table
76 """
77 When I run "behave -f plain features/table.set_column_data.feature"
78 Then it should pass with:
79 """
80 1 scenario passed, 0 failed, 0 skipped
81 2 steps passed, 0 failed, 0 skipped, 0 undefined
82 """
83 And the command output should contain:
84 """
85 | Name | Age |
86 | Alice | 10 |
87 | Bob | 11 |
88 """
89 But note that "the Age table column was added by the step"
90
91
92 Scenario: Modify table cells in a column and ensure changes are shown
93 Given a file named "features/table.modify_column.feature" with:
94 """
95 Feature:
96 Scenario:
97 When I query the database with:
98 | Name | Age |
99 | Alice | 222 |
100 | Bob | 333 |
101 Then note that the "Age" column was modified in the table
102 Then the table contains:
103 | Name | Age |
104 | Alice | 10 |
105 | Bob | 11 |
106 """
107 When I run "behave -f plain features/table.modify_column.feature"
108 Then it should pass with:
109 """
110 1 scenario passed, 0 failed, 0 skipped
111 3 steps passed, 0 failed, 0 skipped, 0 undefined
112 """
113 And the command output should contain:
114 """
115 | Name | Age |
116 | Alice | 10 |
117 | Bob | 11 |
118 """
119 But note that "the Age column was modified in the table"
120 And the command output should not contain:
121 """
122 | Name | Age |
123 | Alice | 222 |
124 | Bob | 333 |
125 """
126
127
128 Scenario: Modify table cells in a column (formatter=pretty with colors)
129 When I run "behave -f pretty features/table.modify_column.feature"
130 Then it should pass with:
131 """
132 1 scenario passed, 0 failed, 0 skipped
133 3 steps passed, 0 failed, 0 skipped, 0 undefined
134 """
135 And the command output should contain:
136 """
137 | Name | Age |
138 | Alice | 10 |
139 | Bob | 11 |
140 """
141 But note that "the Age column was modified in the table"