testing - 为什么 Jest --runInBand 会加速测试?

标签 testing jestjs

我读到 --runInBand flag 在 CI 服务器上将 Jest 测试持续时间加快了 50%。除了让测试在同一个线程中按顺序运行之外,我真的无法在网上找到关于该标志的作用的解释。

为什么在同一个线程中按顺序运行测试会使其更快?直觉上,这不应该让它变慢吗?

最佳答案

阅读您的链接页面和其他一些相关资源(如 this github issue)一些用户发现:

...using the --runInBand helps in an environment with limited resources.

... --runInBand took our tests from >1.5 hours (actually I don't know how long because Jenkins timed out at 1.5 hours) to around 4 minutes. (Note: we have really poor resources for our build server)

正如我们所见,这些用户在他们的机器上的性能得到了提高,即使他们的机器上的资源有限。如果我们从 docs 中读取 --runInBand 标志的作用它说:

Alias: -i. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.

因此,考虑到这些评论和文档,我认为性能的提高是由于现在进程在单个线程中运行。这极大地帮助了有限资源计算机,因为它不必花费内存和时间来处理和处理线程池中的多个线程,而对于有限的资源来说,这项任务可能过于昂贵。

但是,我相信只有在您使用的机器资源有限的情况下才会出现这种情况。如果您使用更“强大”的机器(即:多个内核、体面的 RAM、SSD 等),使用多个线程可能比运行单个线程更好。

关于testing - 为什么 Jest --runInBand 会加速测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43864793/

相关文章:

testing - Grails 域类在测试中未保存

python - 如何测试或模拟 "if __name__ == ' __main_ _'"内容

android - Espresso - 检查使用按下按钮的 Intent 打开了哪个 Activity ?

javascript - 预期调用一个断言但收到零个断言调用

reactjs - Jest 不跟踪符号链接(symbolic link)文件夹中的文件并尝试使用主共享文件夹

ruby-on-rails - 测试从命令行运行但不在 RubyMine 中运行 - 未找到测试

javascript - 如何在 Jest 单元测试中模拟 "this"关键字

node.js - 如何在测试中获取 serverless.yml 中定义的环境变量

javascript - 如何将 Jest 测试移动到/test 文件夹并让它们运行?

testing - 如何从覆盖率统计中排除生成的代码