跳至内容

当你想要进行回归扫描以确保没有出现错误时,需要按顺序运行多个故事。

默认情况下,hitchstory 在遇到第一个错误时会停止。但是可以更改此行为。

代码示例

base.story

Base story:
  given:
    random variable: some value
example1.story

Create file:
  based on: base story
  steps:
    - Create file
Create file again:
  based on: base story
  steps:
    - Create file
example2.story

Create files:
  based on: base story
  steps:
    - Create file

带代码

from hitchstory import StoryCollection, BaseEngine, GivenDefinition, GivenProperty
from pathlib import Path
from ensure import Ensure

class Engine(BaseEngine):
    given_definition=GivenDefinition(
        random_variable=GivenProperty()
    )

    def create_file(self, filename="step1.txt", content="example"):
        with open(filename, 'w') as handle:
            handle.write(content)

按文件顺序运行所有故事

results = StoryCollection(
    [
        "base.story",
        "example1.story",
        "example2.story",
    ],
    Engine()
).ordered_by_file().play()
Ensure(results.all_passed).is_true()

将输出

RUNNING Base story in /path/to/working/base.story ... SUCCESS in 0.1 seconds.
RUNNING Create file in /path/to/working/example1.story ... SUCCESS in 0.1 seconds.
RUNNING Create file again in /path/to/working/example1.story ... SUCCESS in 0.1 seconds.
RUNNING Create files in /path/to/working/example2.story ... SUCCESS in 0.1 seconds.

按名称顺序运行 'example1.story' 中的所有测试

StoryCollection(
    Path(".").glob("*.story"), Engine()
).in_filename("example1.story").ordered_by_name().play()

将输出

RUNNING Create file in /path/to/working/example1.story ... SUCCESS in 0.1 seconds.
RUNNING Create file again in /path/to/working/example1.story ... SUCCESS in 0.1 seconds.

对一组故事使用 .one() 将失败

StoryCollection(Path(".").glob("*.story"), Engine()).one()

可执行规范

multiple.story storytests 自动生成的文档。