gpt4 book ai didi

angularjs - Protractor 的 spec.js 文件中的 describe() 和 it() 有什么区别?

转载 作者:行者123 更新时间:2023-11-28 19:52:10 24 4
gpt4 key购买 nike

当用 Protractor 在 spec.js 文件中编写测试用例时,有 2 个字段显示 describe() 和 it()。它们的具体用途是什么以及何时使用?

//规范.js

describe('Protractor Demo App', function() {
it('should have a title', function() {
..
});
});

最佳答案

希望通过阅读本文,您会找到答案。

spec.js 关于(Jasmine 一个用于测试 JavaScript 代码的行为驱动开发框架如何工作)

它有两个主要功能

Suite describe Your Tests

A test suite begins with a call to the global Jasmine function describe with two parameters: a string and a function. The string is a name or title for a spec suite - usually what is being tested. The function is a block of code that implements the suite.

Specs

Specs are defined by calling the global Jasmine function it, which, like describe takes a string and a function. The string is the title of the spec and the function is the spec, or test. A spec contains one or more expectations that test the state of the code. An expectation in Jasmine is an assertion that is either true or false. A spec with all true expectations is a passing spec. A spec with one or more false expectations is a failing spec.

describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});

It's Just Functions

Since describe and it blocks are functions, they can contain any executable code necessary to implement the test. JavaScript scoping rules apply, so variables declared in a describe are available to any it block inside the suite.

更多详情可以看this link

关于angularjs - Protractor 的 spec.js 文件中的 describe() 和 it() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46170937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com