Test Definition Classes
Module
A Module can be defined using Module test definition class or TestModule decorator.
1 |
|
or inline as
1 | with Module("module"): |
Suite
A Suite can be defined using Suite test definition class or TestSuite decorator.
1 |
|
or inline as
1 | with Suite("My suite"): |
Feature
A Feature can be defined using Feature test definition class or TestFeature decorator.
1 |
|
or inline as
1 | with Feature("My feature"): |
Test
A Case can be defined using Test test definition class or TestCase decorator.
1 |
|
or inline as
1 | with Test("My testcase"): |
✋ Note that here the word
testis used to define a Case to match the most common meaning of the wordtest. When someone says they will run atestthey most likely mean they will run a test Case.
Scenario
A Scenario can be defined using Scenario test definition class or TestScenario decorator.
1 |
|
or inline as
1 | with Scenario("My scenario"): |
Check
A Check can be defined using Check test definition class or TestCheck decorator
1 |
|
or inline as
1 | with Check("My check"): |
and is usually used inside either Test or Scenario to define an inline sub-test
1 | with Scenario("My scenario"): |
Critical, Major, Minor
A Critical, Major, or Minor checks can be defined using Critical, Major or Minor test definition class, respectively, or similarly using TestCritical, TestMajor, TestMinor decorators
1 |
|
or inline as
1 | with Critical("My critical check"): |
and are usually used inside either Test or Scenario to define inline sub-tests.
1 | with Scenario("My scenario"): |
These classes are usually used for the classification of checks during reporting.
1 | 1 scenario (1 ok) |
Example
An Example can only be defined inline using Example test definition class. There is no decorator to define it outside of existing test. An Example is a sub-type of a Test Type and is used to define one or more sub-tests. Usually, Examples are created automatically using Outlines.
1 | with Scenario("My scenario"): |
Outline
An Outline can be defined using Outline test definition class or TestOutline decorator. An Outline is a sub-type of a Test type but you can change the type by passing it another Type or a Sub-Type such as Scenario or Suite etc.
However, because Outlines are meant to be called from other tests or used with Examples it is best to define an Outline using TestOutline decorator as follows.
1 | from testflows.core import * |
When Examples are defined for the Outline and an outline is called with no arguments from a test that is of a higher Type than the Type of outline itself, then when called, the outline will iterate over all the examples defined in the Examples table. For example, if you run the example above that executes the outline with no arguments, you will see that the outline iterates over all the examples in the Examples table, where each example, a row in the examples table, defines the values of the arguments for the outline.
1 | Jul 05,2020 18:16:34 ⟥ Scenario outline |
If we run the same outline with arguments, then the outline will not use the Examples but instead will use the argument values that were provided to the outline. For example,
1 | with Scenario("My scenario"): |
will produce the following output.
1 | Jul 05,2020 18:23:02 ⟥ Scenario My scenario |
Combination
A Combination is not meant to be used explicitly, and in most cases it is only used internally to represent each combination of a Sketch.
Sketch
A Sketch is defined using the TestSketch decorator. In most cases you should not use Sketch test definition class directly as it will not execute its Combinations. A Sketch is a sub-type of a type Test but you can specify a different type. For example, you can pass a specific Type or a Sub-Type such as Scenario, Suite, or Feature etc. when defining a TestSketch.
Because Sketchs are designed to execute different Combinations, one for each Combination defined by the either() function, it is best to define a Sketch only using a TestSketch decorator.
✋ TestSketch is designed to work with either() function that is used to define combination variables and their possible values.
For example,
1 | def add(a, b): |
The TestSketch above calls the add() function with different combinations of its a and b parameters.
The Sketch checks combinations when a argument is either 1 or 2, and b argument is either 2 or 3.
Therefore, the following combination patterns are covered:
pattern #0: add(1,2)pattern #1: add(1,3)pattern #2: add(2,2)pattern #3: add(2,3)
You can see this from the output of the test.
1 | Sep 21,2023 13:42:38 ⟥ Scenario my sketch |
See Using Sketches for more details.
Iteration
An Iteration is not meant to be used explicitly, and in most cases it is only used internally to implement test repetitions.
RetryIteration
A RetryIteration is not meant to be used explicitly and, in most cases, is only used internally to implement test retries.
Step
A Step can be defined using Step test definition class or TestStep decorator.
1 |
|
A TestStep can be made specific by passing it a specific [BBD] step Sub-Type.
1 |
|
A Step can be defined inline as
1 | with Step("step"): |
Given
A Given step is used to define preconditions or setup and is always treated as a mandatory step that can’t be skipped because MANDATORY flag will be set by default. It is defined using Given test definition class or using TestStep with Given passed as the Sub-Type.
1 |
|
or inline as
1 | with Given("I have something"): |
Background
A Background step is used to define a complex preconditions or setup, usually containing multiple Given‘s and can be defined using Background test definition class or TestBackground decorator. It is treated as a mandatory step that can’t be skipped.
1 |
|
or inline as
1 | with Background("My complex setup"): |
When
A When step is used to define an action within a Scenario. It can be defined using When test definition class or using TestStep decorator with When passed as the Sub-Type.
1 |
|
or inline as
1 | with When("I do some action"): |
And
An And step is used to define a step of the same Sub-Type as the step right above it. It is defined using And test definition class.
✋ It does not make sense to use TestStep decorator to define it, so always define it inline.
1 | with When("I do some action"): |
or
1 | with Given("I have something"): |
✋
TypeErrorexception will be raised if the And step is defined where it has no siblings. For example,
1
2
3
4
5 with Given("I have something"):
# TypeError exception will be raised on the next line
# and can be fixed by changing the `And` step into a `When` step
with And("I do something"):
passwith the exception being as follows.
1 TypeError: `And` subtype can't be used here as it has no sibling from which to inherit the subtype
✋
TypeErrorexception will also be raised if the Type of the sibling does not match the Type of the And step. For example,
1
2
3
4
5
6
7 with Scenario("My scenario"):
pass
# TypeError exception will be raised on the next line
# and can be fixed by changing the `And` step into a `When` step
with And("I do something"):
passwith the exception being as follows.
1 TypeError: `And` subtype can't be used here as it sibling is not of the same type
By
A By step is usually used to define a sub-step using By test definition class.
1 | with When("I do something"): |
Then
A Then step is used to define a step that usually contains a positive assertion. It can be defined using Then test definition class or using TestStep decorator with Then passed as the Sub-Type.
1 |
|
or inline as
1 | with Then("I expect something"): |
But
A companion of the Then step is a But step and is used to define a step that usually contains a negative assertion. It can be defined using But test definition class or using TestStep decorator with But passed as the Sub-Type.
1 |
|
or inline as
1 | with But("I check something is not true"): |
Finally
A Finally step is used to define a cleanup step and is treated as a mandatory step that can’t be skipped because MANDATORY flag will be set by default.
It can be defined using Finally test definition class or using TestStep decorator with Finally passed as the Sub-Type.
1 |
|
or inline as
1 | with Finally("I clean up"): |
The TE flag is always set for Finally steps as multiple Finally steps can be defined back to back and the failure of a previous step should not prevent execution of other Finally steps that follow.