lab 常用配置参数 代码片段

本文介绍HAPI测试框架的基本用法,包括如何启用内存泄漏检测、设置测试超时及并行执行。通过代码示例展示如何使用test和experiment函数进行单元测试,以及如何跳过特定测试和设置测试超时。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、--leaks 启用内存泄漏检测,并在检测到时向您发出警告

2、代码片段

experiment('getting started with hapi testing,', () => {
  // 这种写法会跳过测试
  test('lab considers this test as TOOD and skips it')
  // 这种写法不会跳过测试
  test('always succeeding :)', () => { })
})

3、testexperiment常用参数

timeout: 设置特定的超时(以毫秒为单位)。 默认为2,000 ms或-m的值
parallel: 在每个实验级别内激活并行执行测试。 默认为false(串行执行)
skip: 跳过执行。 设置父级跳过后,无法在子级中覆盖
only: 使用skip标记所有其他测试或实验

为每个测试并行运行的实验提供一个选项对象:

experiment('getting started with hapi testing,', { parallel: true }, () => {  
  test('lab considers this test as TODO and skips it')

  test('always succeeding :)', { timeout: 5000 }, () => {})
})

设置only和skip选项的另一种方法是链接具有相同名称的方法,如下所示:

experiment('getting started with hapi testing,', { parallel: true }, () => {  
  test.skip('lab considers this test as TODO and skips it')
  test('always succeeding :)', { timeout: 5000 }, () => {})
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值