当前位置: 代码迷 >> 综合 >> 测试结构
  详细解决方案

测试结构

热度:22   发布时间:2024-01-30 12:22:15.0

测试结构

从 Mocha 借鉴过来的测试接口提供了 describe(),context(),it()和specify()方法。

context() 与 describe() 相同, specify() 与 it() 相同,所以选择最适合你的就行了。

// -- Start: Our Application Code --
function add (a, b) {return a + b
}function subtract (a, b) {return a - b
}function divide (a, b) {return a / b
}function multiply (a, b) {return a * b
}
// -- End: Our Application Code --// -- Start: Our Cypress Tests --
describe('Unit test our math functions', function() {context('math', function() {it('can add numbers', function() {expect(add(1, 2)).to.eq(3)})it('can subtract numbers', function() {expect(subtract(5, 12)).to.eq(-7)})specify('can divide numbers', function() {expect(divide(27, 9)).to.eq(3)})specify('can multiply numbers', function() {expect(multiply(5, 4)).to.eq(20)})})
})
// -- End: Our Cypress Tests --
  相关解决方案