Skip to main content

编写系统测试

¥Writing system tests

系统测试验证 Stylelint 是否按预期工作。它们是继单元测试和集成测试之后防止回归的另一道防线。

¥System tests verify that Stylelint works as expected. They are another line of defense against regressions, after the unit tests and integration tests.

每个系统测试都断言,在给定配置和样式表的情况下,我们最终会得到一些预期的输出。

¥Each of these system tests asserts that we end up with some expected output, given a configuration and a stylesheet.

这些测试不应该是全面和系统的(单元测试应该如此)。他们应该重现真实的用例并验证这些用例是否按预期工作。

¥These tests should not be comprehensive and systematic (the unit tests should). They should reproduce real use-cases and verify that those use-cases work as expected.

Jest 快照

¥Jest snapshots

测试使用 Jest 快照,因此我们可以轻松地:

¥The tests use Jest snapshots, so we can easily:

  • 针对潜在的大对象和字符串进行断言

    ¥assert against potentially large objects and strings

  • 根据需要更新期望。

    ¥update expectations as needed.

模式

¥The pattern

要添加系统测试,你应该:

¥To add a system test, you should:

  • 将测试用例文件夹添加到 system-tests/,增加现有测试用例的数量

    ¥add a test-case folder to system-tests/ incrementing the number from existing test cases

  • 添加配置文件和样式表

    ¥add a configuration file and a stylesheet

  • 按照现有测试建立的格式添加 fs.test.jsno-fs.test.js,并使用 systemTestUtils

    ¥add a fs.test.js and no-fs.test.js following the format established by existing tests, and using the systemTestUtils

  • 拍摄 output 的快照

    ¥take a snapshot of output