如何防止测试在第一个失败的测试用例上停止? [英] How do you prevent the tests from stopping on the first failed test case?
问题描述
我正在尝试检查不同页面上是否存在某些内容.例如:
I'm attempting to check if certain pieces of content are present, on different pages. For example:
const contentCount = Selector('.some-element').childElementCount
.expect(contentCount).gte(1, 'The related content is missing.')
...正常工作,除了测试在第一个断言失败之后停止之外.这不是理想的选择,因为我试图生成一次显示所有失败的断言的报告.
... Which works fine, except that the testing stops after the first assertion fails. This isn't ideal as I'm trying to generate a report that shows ALL of the failed assertions at once.
如何使测试在断言失败后继续运行?
How do I get the test to keep running after a failed assertion?
推荐答案
首先从主题回答您的问题(如何防止测试在第一个失败的测试用例上停止).
Answering your question from the subject first (how to prevent the test from stopping on the first failed test case).
TestCafe将运行所有测试,即使其中一项失败也是如此.您可能希望将具有多个断言的单个测试用例拆分为每个测试具有一个断言的多个测试用例,以获得适当的报告.
TestCafe will run all tests even if one of them failed. You might want to split your single test case with multiple assertions into multiple test cases with a single assertion per test to obtain a proper report.
现在,从身体上回答您的问题(在失败的断言后如何继续运行).
Now, answering your question from the body (how to keep running after a failed assertion).
目前,无法在测试执行期间跳过失败的断言.如果断言失败,则TestCafe认为出了点问题,因此整个测试都失败了.但是,如果您不希望断言使测试失败,则可以为其添加条件;否则,请执行以下步骤.例如:
At the moment, there is no way to skip a failed assertion during the test execution. TestCafe considers that something went wrong if an assertion failed, so the entire test fails. However, if you don't want an assertion to fail a test, you may add a condition for it; e.g.:
if (contentCount > 0)
await t.expect(contentCount).gte(1, 'The related content is missing.')
但是,这看起来并不像直接可预测的测试逻辑.因此,我选择将一个测试分为多个测试,每个测试一个断言.
But, this does not look like straight and predictable test logic. So, I would choose splitting a test into multiple tests with one assertion per test.
这篇关于如何防止测试在第一个失败的测试用例上停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!