【问题标题】:Detox - How to get a previous spec to run before a new spec runs to avoid duplicate test steps?Detox - 如何在新规范运行之前运行以前的规范以避免重复的测试步骤?
【发布时间】:2018-08-23 04:46:59
【问题描述】:

所以我写了一个登录用户的测试:

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 在继续执行新步骤之前运行第一次登录测试?

不幸的是,beforeEach it('应该授予具有有效凭据的用户访问权限')不起作用,所以我在语法中遗漏了一些东西。

【问题讨论】:

    标签: react-native automated-tests detox greybox


    【解决方案1】:

    这与 Detox 无关,此 describe/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
      }
    });
    

    【讨论】:

      【解决方案2】:

      最佳做法是在测试中使用驱动程序。 您可以查看这些幻灯片: http://slides.com/shlomitoussiacohen/testing-react-components#/7

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-27
        • 2017-04-28
        • 1970-01-01
        • 2013-07-06
        • 2021-09-19
        • 1970-01-01
        • 2017-06-14
        相关资源
        最近更新 更多