Cypress beforeEach 设置 cy.request

Cypress beforeEach setup with cy.request

我的测试需要在数据库中创建一些项目,所以在每次测试之前,我很少请求 API 使用 cy.request()

创建它们

这是好的做法还是我应该以其他方式准备设置?

beforeEach(() => {
  cy.request(someUrl)
  cy.request(anotherUrl)
})

it('test smth', () => {
  // do some stuff
})

it('test something', () => {
  // do some stuff
})

是的,这是一个很好的做法。阅读更多 here. Also, you can watch a brilliant presentation by Brian Mann here.

请记住,测试应该始终能够 运行 彼此独立并且仍然通过。阅读更多 here.