当前位置: 首页 > 文档资料 > Electron 中文文档 >

测试

优质
小牛编辑
135浏览
2023-12-01

我们的目的是保持 Electron 代码的高覆盖率。 我们要求所有的pull request不仅要通过所有现有的测试,还要增加新的测试来覆盖变更的代码和新的场景。 我们要尽可能多地覆盖Electron应用中的代码路径和用例,以确保我们发布的应用程序都能拥有更少的bug。

这个仓库为 JavaScript 和 C ++ 提供了linting 规则 - 以及单元和集成测试。 通过 coding-style文档来学习更多的Electron's编码风格

Testing

We aim to keep the code coverage of Electron high. We ask that all pull request not only pass all existing tests, but ideally also add new tests to cover changed code and new scenarios. Ensuring that we capture as many code paths and use cases of Electron as possible ensures that we all ship apps with fewer bugs.

This repository comes with linting rules for both JavaScript and C++ – as well as unit and integration tests. To learn more about Electron's coding style, please see the coding-style document.

提示

为确保您的JavaScript符合Electron编码风格,请执行npm run lint-js,它将针对Electron本身以及单元测试运行standard测试。 如果您正在使用带有插件/插件系统的编辑器,那么可以使用StandardJS addons之类的插件在你提交代码前来检查编码规范。

若要用参数运行standard测试,首先执行npm run lint-js -- 然后输入要传递给standard测试的参数。

要确保您的C ++代码符合Electron编码风格,请执行npm run lint-cpp,它将会执行cpplint脚本。 我们建议您使用clang-format并准备一个简短的教程。

这个仓库中没有太多的Python代码,但是它也受编码风格规范的约束。使用npm run lint-py来检查Python的编码风格规范。当然你也可以使用pylint

Linting

To ensure that your JavaScript is in compliance with the Electron coding style, run npm run lint-js, which will run standard against both Electron itself as well as the unit tests. If you are using an editor with a plugin/addon system, you might want to use one of the many StandardJS addons to be informed of coding style violations before you ever commit them.

To run standard with parameters, run npm run lint-js -- followed by arguments you want passed to standard.

To ensure that your C++ is in compliance with the Electron coding style, run npm run lint-cpp, which runs a cpplint script. We recommend that you use clang-format and prepared a short tutorial.

There is not a lot of Python in this repository, but it too is governed by coding style rules. npm run lint-py will check all Python, using pylint to do so.

单元测试

要运行所有单元测试,请执行 npm run test。 单元测试其实也是一个Electron应用!你可以在spec 文件夹中找到它。 请注意,单元测试也有自己的 package.json,因此它的依赖没有在最顶层的package.json中定义。

若要通过匹配模式运行单个测试,可以执行 npm run test -- -g=PATTERN,把PATTERN 替换为匹配某个测试的正则表达式。 例:如果想运行IPC测试,你可以执行npm run test -- -g ipc

Unit Tests

To run all unit tests, run npm run test. The unit tests are an Electron app (surprise!) that can be found in the spec folder. Note that it has its own package.json and that its dependencies are therefore not defined in the top-level package.json.

To run only specific tests matching a pattern, run npm run test -- -g=PATTERN, replacing the PATTERN with a regex that matches the tests you would like to run. As an example: If you want to run only IPC tests, you would run npm run test -- -g ipc.

在Windows10上测试

一些 Windows 10 设备上没有默认安装Meriryo字体,这会导致字体回退测试的失败。 要安装Meiryo字体:

  1. 按下Windows key并搜索 管理可选功能
  2. 单击添加功能
  3. 选择Japanese Supplemental Fonts并单击 安装

由于浮点数精度误差,某些依赖于精确像素测量的测试可能无法正常在Hi-DPI屏幕的设备上工作。 为了使这些测试能正常运行,请确保设备的缩放比为100%。

要配置缩放比:

  1. 按下Windows key并搜索显示设置.
  2. Scale and layout下,确保缩放比为100%。

Testing on Windows 10 devices

Some Windows 10 devices do not ship with the Meiryo font installed, which may cause a font fallback test to fail. To install Meiryo: 1. Push the Windows key and search for Manage optional features. 1. Click Add a feature. 1. Select Japanese Supplemental Fonts and click Install.

Some tests which rely on precise pixel measurements may not work correctly on devices with Hi-DPI screen settings due to floating point precision errors. To run these tests correctly, make sure the device is set to 100% scaling.

To configure display scaling: 1. Push the Windows key and search for Display settings. 1. Under Scale and layout, make sure that the device is set to 100%.