Detox

针对移动应用的灰盒式端到端测试和自动化框架。(Gray Box End-to-End Testing and Automation Framework for Mobile Apps)

Detox

移动应用的灰盒端到端测试和自动化库。

Detox 测试是什么样子的?

这是一个登录屏幕的测试,它像实际用户一样在设备/模拟器上运行。

describe('Login flow', () => {
  it('should login successfully', async () => {
    await device.reloadReactNative();
    await element(by.id('email')).typeText('john@example.com');
    await element(by.id('password')).typeText('123456');
    await element(by.text('Login')).tap();
    await expect(element(by.text('Welcome'))).toBeVisible();
    await expect(element(by.id('email'))).toNotExist();
  });
});

现在就开始使用 Detox now!

关于 Detox

高速的原生移动开发要求我们采用持续集成工作流程,这意味着我们对人工QA的依赖必须大幅下降。Detox 在您的移动应用在真实设备/模拟器中运行时对其进行测试,就像真实用户一样与它进行交互。

移动端自动化测试最困难的部分是测试金字塔的顶端--E2E。E2E测试的核心问题是松散性--测试通常不是确定性的。我们相信,解决松散性的唯一方法是从黑盒测试转向灰盒测试。这就是 Detox 发挥作用的地方。

  • 跨平台。用 JavaScript 编写跨平台测试。目前支持 iOS 和 Android。
  • 在设备上运行(iOS 还不支持)。通过在设备/模拟器上测试您的应用程序,就像真正的用户一样,获得出货的信心。
  • 自动同步。通过监控您的应用程序中的异步操作,从根本上防止漏洞。
  • 专为 CI 而生:在 CI 平台上执行 E2E 测试,如 Travis,而不感到痛苦。
  • 测试运行器独立。使用 Jest、Mocha、AVA 或任何其他你喜欢的 JavaScript 测试运行器(破坏者:我们有我们的最爱)。
  • 可调试。现代 async-await API 允许异步测试中的断点按预期工作。

支持的版本

环境

  • OS: macOS 10.14 (Mojave) 或更高版本
  • Xcode: 10.2 或更高版本
    • iOS Simulator Runtime: iOS 12.2 或更高版本

React Native

Detox 从底层构建,支持 React Native 项目以及纯本地项目。

以下是已经测试过的 React Native 版本。

iOS Android
<=0.63 <=0.56 - Full support
>=0.57 <=0.63 - Visibility edge-case: see this RN issue*

未来的版本很可能被支持,但还没有经过测试。如果您发现较新的 React Native 版本存在特定问题,请打开问题。

开始使用 Detox

阅读 入门指南,在 10 分钟内让 Detox 在您的应用程序上运行。

文件目录

文档目录 中进一步探索如何使用 Detox。

实际应用

打开 React Native 演示项目,按照说明操作。

不使用 React Native 吗,我们也有一个 纯原生的演示项目

反思核心原则

我们认为,只有重新思考整个方法的一些原则,才能解决移动端到端测试的核心难题。看看 Detox 的 不同做法

为 Detox 做贡献

从第一次提交开始开源。如果你有兴趣帮助我们完成路线图,请查看标有  寻找贡献者 标签的问题。如果你遇到了一个 bug 或者想提出一个新的功能,请打开一个问题。

请阅读 Detox 贡献指南,深入了解 Detox 核心。

许可证

  • Detox 本身和这个 repo 中的所有原始源码都是 MIT 的。
  • Detox 依赖于一些重要的依赖性,它们各自的许可证是:


(The first version translated by vz on 2020.08.22)

主要指標

概覽
名稱與所有者wix/Detox
主編程語言JavaScript
編程語言Java (語言數: 14)
平台Mac
許可證MIT License
所有者活动
創建於2016-06-15 11:58:01
推送於2025-06-10 11:30:01
最后一次提交2025-05-26 08:50:24
發布數690
最新版本名稱20.39.0 (發布於 2025-05-26 08:50:24)
第一版名稱v0.2.0 (發布於 2012-08-30 19:07:33)
用户参与
星數11.5k
關注者數372
派生數1.9k
提交數5.9k
已啟用問題?
問題數2868
打開的問題數190
拉請求數1427
打開的拉請求數9
關閉的拉請求數330
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

Detox

Gray box end-to-end testing and automation library for mobile apps.

NPM Version
NPM Downloads
Build Status

What does a Detox test look like?

This is a test for a login screen, it runs on a device/simulator like an actual user:

describe('Login flow', () => {
    
  it('should login successfully', async () => {
    await device.reloadReactNative();
    await expect(element(by.id('email'))).toBeVisible();
      
    await element(by.id('email')).typeText('john@example.com');
    await element(by.id('password')).typeText('123456');
    await element(by.text('Login')).tap();
      
    await expect(element(by.text('Welcome'))).toBeVisible();
    await expect(element(by.id('email'))).toNotExist();
  });
  
});

About

High velocity native mobile development requires us to adopt continuous integration workflows, which means our reliance on manual QA has to drop significantly. Detox tests your mobile app while it's running in a real device/simulator, interacting with it just like a real user.

The most difficult part of automated testing on mobile is the tip of the testing pyramid - E2E. The core problem with E2E tests is flakiness - tests are usually not deterministic. We believe the only way to tackle flakiness head on is by moving from black box testing to gray box testing. That's where Detox comes into play.

  • Cross Platform: Write cross-platform tests in JavaScript. Currently supports iOS and Android.
  • Runs on Devices (not yet supported on iOS): Gain confidence to ship by testing your app on a device/simulator just like a real user.
  • Automatically Synchronized: Stops flakiness at the core by monitoring asynchronous operations in your app.
  • Made For CI: Execute your E2E tests on CI platforms like Travis without grief.
  • Test Runner Independent: Use Mocha, AVA, or any other JavaScript test runner you like.
  • Debuggable: Modern async-await API allows breakpoints in asynchronous tests to work as expected.

Supported versions

Environment

  • OS: MacOS 10.13 (High Sierra) or higher.
  • Xcode: 10.1 or higher.

React Native

Detox is built from the ground up to support React Native projects as well as pure native ones.

The following React Native versions have been tested: