Skip to main content

TestCase

TestCase 对应于测试文件中的每个 test(title, testFunction) 调用。当单个 test(title, testFunction) 在多个项目中运行或重复多次时,它将在相应项目的套件中具有多个 TestCase 对象。

testCase.ok()

Added in: v1.10

测试是否被认为运行良好。非 ok 测试会使测试运行失败,并返回非零退出代码。

testCase.outcome()

Added in: v1.10
  • returns: <"skipped"|"expected"|"unexpected"|"flaky">#

此测试的测试结果。请注意,结果与 testResult.status 不同:

  • 预期失败且实际失败的测试为 'expected'
  • 在第二次重试时通过的测试为 'flaky'

testCase.titlePath()

Added in: v1.10

返回从根目录到此测试的标题列表。

testCase.annotations

Added in: v1.10

适用于当前测试的注释列表。包括来自测试的注释、来自测试所属的所有 test.describe(title, callback) 组的注释以及测试文件的文件级注释。

注释在测试执行期间通过 testInfo.annotations 可用。

了解有关 测试注释 的更多信息。

testCase.expectedStatus

Added in: v1.10
  • type:<"passed"|"failed"|"timedOut"|"skipped"|"interrupted">

预期测试状态。

另请参阅 testResult.status 以获取实际状态。

testCase.id

Added in: v1.25

基于测试文件名、测试标题和项目名称计算的唯一测试 ID。测试 ID 可用作历史 ID。

testCase.location

Added in: v1.10

定义测试的源位置。

testCase.parent

Added in: v1.10

此测试用例所属的套件。

testCase.repeatEachIndex

Added in: v1.10

包含在“重复每个”模式下运行时的重复索引。通过将 --repeat-each 传递给 命令行 来启用此模式。

testCase.results

Added in: v1.10

此测试每次运行的结果。

testCase.retries

Added in: v1.10

配置中为此测试提供的最大重试次数。

了解有关 测试重试 的更多信息。

testCase.timeout

Added in: v1.10

给测试的超时时间。受 testConfig.timeouttestProject.timeouttest.setTimeout(timeout)test.slow()testInfo.setTimeout(timeout) 的影响。

testCase.title

Added in: v1.10

传递给 test(title, testFunction) 调用的测试标题。