React native 解毒-如何在运行新规范之前运行以前的规范,以避免重复的测试步骤?

React native 解毒-如何在运行新规范之前运行以前的规范,以避免重复的测试步骤?,react-native,automated-tests,detox,greybox,React Native,Automated Tests,Detox,Greybox,因此,我编写了一个测试,用于登录用户: describe('Login', () => { beforeEach(async () => { await device.reloadReactNative() }) it('Should grant access to a user with valid credentials', async () => { test code }) }) 现在,我正在编写一个新规范来注销用户,因此,我不想再次编

因此,我编写了一个测试,用于登录用户:

describe('Login', () => {

beforeEach(async () => {
    await device.reloadReactNative()
  })

  it('Should grant access to a user with valid credentials', async () => {
    test code
  })
})
现在,我正在编写一个新规范来注销用户,因此,我不想再次编写相同的测试代码,而是希望登录规范在注销规范中运行。我可以想象它看起来像:

describe('Log Out', () => {

beforeEach(async () => {
    await device.reloadReactNative()
    it ('Should grant access to a user with valid credentials')
  })

  it('A User Logs Out', async () => {
    test code
  })
在继续新步骤之前,我如何让Detox运行第一个登录测试


不幸的是,Beforeach it(“应该授予具有有效凭据的用户访问权限”)不起作用,因此我在语法中遗漏了一些内容。

这与解毒无关,这个descripe/it API与您正在使用的测试运行程序相关。无论如何,请使用以下函数:

describe('Login', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
    await grantAccessToUserWithValidCredentials();
  });

  it('A User Logs Out', async () => {
    // here the app is ready for you specific log out use case 
  });

  async function grantAccessToUserWithValidCredentials() {
    //grant it
  }
});

最佳实践是在测试中使用驱动程序。 您可以查看以下幻灯片: