测试时如何顺序运行子项目测试(包括设置方法) [英] How to run subprojects tests (including setup methods) sequentially when testing

查看:12
本文介绍了测试时如何顺序运行子项目测试(包括设置方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EDIT4 水平线下方的大部分文字与真正的问题没有任何关系.一开始我认为分叉是问题所在,但事实并非如此.

EDIT4 Most of the text below the horizontal rule doesn't have anything to do with the real problem. At the beginning I thought forking is the problem, but that is not true.

我正在尝试运行聚合子项目的所有测试.在子项目中的所有测试之前应该运行一个设置方法,在子项目中的测试之后应该运行一个清理方法.

I'm trying to run all the tests of an aggregates subprojects. Before all the tests in a subproject a setup method should run, and after the tests in a subproject a cleanup method should run.

在为聚合项目运行测试任务时,我期望以下顺序

When running the test task for the aggregate project, I expect the following sequence

  • 项目A的setup方法被调用
  • 执行项目 A 的测试
  • 调用项目 A 的清理方法
  • 项目 B 也是如此

但是顺序是:

  • 调用项目 A 和 B 的设置方法
  • 执行项目 A 的测试
  • 执行项目 B 的测试
  • 调用项目 A 和 B 的清理方法

可以在此处找到具有此行为的构建脚本.

A build script having this behaviour can be found here.

如何解决这个问题以获得我的预期序列?

How can I fix this problem to get my expected sequence?

我正在使用分叉在我的子项目中运行测试.对于每个子项目,mongo db 在测试之前启动并停止测试后.

I'm using forking to run the tests in my subprojects. For every subproject a mongo db is started before the tests and stopped after the tests.

一个项目中的测试按顺序运行;如果我为单个项目运行测试,这很有效.

The tests within one project run sequentially; this works well if I run the tests for a single project.

但如果我为项目根(包含子项目的聚合)运行任务 test,我希望按顺序启动分叉的 jvm,即

But if I run the task test for project root (the aggregate containing the sub projects), I want the forked jvms to be started sequentially, i.e.

  1. 项目 A 的 jvm 被分叉并执行其测试
  2. 项目 B 的 jvm 被分叉并执行其测试
  3. ...

但看起来 jvm 是并行启动的;这不是我想要的.

But it looks like the jvms are started in parallel; this is not what I want.

我尝试了以下方法(根据文档,它应该已经设置为 1):

I tried the following (which should be set to 1 already, according to the documentation):

  concurrentRestrictions in Test := Seq(
    Tags.limit(Tags.ForkedTestGroup, 1)
  )

但它没有用.直接启动测试任务后,如下从我的设置方法打印(在打印任何测试日志之前):

But it didn't work. Directly after starting the test task, the following is printed (before any test log is printed) from my setup method:

startupDb, thread name = pool-4-thread-5 
startupDb, thread name = pool-4-thread-7 
startupDb, thread name = pool-4-thread-2 
startupDb, thread name = pool-4-thread-6 
startupDb, thread name = pool-4-thread-8
startupDb, thread name = pool-4-thread-3 
startupDb, thread name = pool-4-thread-9

这些是我的测试相关设置:

These are my test related settings:

parallelExecution in Test := false,
testOptions in Test += Tests.Setup( () => MongoTest.startupDb() ),
testOptions in Test += Tests.Cleanup( () => MongoTest.shutdownDb() ),
fork in Test := true,
concurrentRestrictions in Test := Seq(
  Tags.limit(Tags.ForkedTestGroup, 1)
)

使用分叉对我来说很重要,但方式如上所述.

It's important for me to use forking, but in the way as described above.

我在 Windows 7 上使用 sbt 0.13.0.

I'm using sbt 0.13.0 on Windows 7.

编辑我用示例构建创建了一个要点.

EDIT2文档上面写着:

通过设置Tags.ForkedTestGroup标签的限制来控制允许同时运行的fork JVM数量,默认为1

Control the number of forked JVMs allowed to run at the same time by setting the limit on Tags.ForkedTestGroup tag, which is 1 by default

所以理论上这应该可行.这是一个错误吗?如果没有,我该如何做到这一点?

So this should work theoretically. Is this a bug? If not, how can I manage to do that?

EDIT3 看起来分叉不是问题.问题是所有子项目都会立即调用设置方法.

EDIT3 It looks like forking is not the problem. The problem is that the setup methods are called immediately for all subprojects.

推荐答案

嗯.琐碎的答案转换为评论.听起来您问的是在另一个问题中已解决的相同问题(请参阅评论).答案似乎是

Hmm. Trivial answer convert to comment. It sounds like you are asking the same question that got solved in the other question (see comments). The answer seems to be

parallelExecution in ThisBuild := false

我发现另一篇建议的博客文章

and I found another blog post that suggested

parallelExecution in Global := false

作为答案.全局"答案还建议关闭并行执行,例如编译,但这可能不如运行测试重要.

to be the answer. The "Global" answer also suggested that would turn off parallel execution for things like compilation but that's probably less important than running tests.

这篇关于测试时如何顺序运行子项目测试(包括设置方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆