玩!框架:定制运行哪些测试 [英] Play! framework: customize which tests are run

查看:69
本文介绍了玩!框架:定制运行哪些测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有戏! 2适用于Scala应用程序,我正在使用Specs2进行测试.我可以使用test命令运行所有测试,也可以使用test-only MyParticularSpec运行特定的规范.

I have a Play! 2 for Scala application, and I am using Specs2 for tests. I can run all tests with the test command, or a particular specification with test-only MyParticularSpec.

我想做的是标记一些特定的规范,甚至在规范中标记单个方法,以便执行以下操作:

What I would like to do is mark some particular specifications, or even single methods inside a specification, in order to do things like:

  • 运行所有非集成(即不访问外部资源)的测试
  • 在写模式下运行所有​​不访问外部资源的测试(但仍在运行读取测试)
  • 运行除给定测试以外的所有测试

以此类推.

我想类似的事情应该可行,也许可以通过添加一些注释来实现,但是我不确定该怎么做.

I guess something like that should be doable, perhaps by adding some annotations, but I am not sure how to go for it.

有没有一种机制可以选择性地运行某些测试,而不能选择性地运行其他测试?

Does there exist a mechanism to selectively run some tests and not other ones?

编辑,我已经在使用test-only时回答了自己.命令行选项仍然不适用于test任务.按照 sbt指南,我尝试创建一个其他sbt配置,例如

EDIT I have answered myself when using test-only. Still the command line option does not work for the test task. Following the sbt guide I have tried to create an additional sbt configuration, like

object ApplicationBuild extends Build {
  // more settings
  lazy val UnitTest = config("unit") extend(Test)
  lazy val specs = "org.scala-tools.testing" %% "specs" % "1.6.9" % "unit"

  val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA)
    .configs(UnitTest)
    .settings(inConfig(UnitTest)(Defaults.testTasks) : _*)
    .settings(
      testOptions in UnitTest += Tests.Argument("exclude integration"),
      libraryDependencies += specs
    )
}

当我传递不带选项的参数时(例如,当我放入Test.Argument("plan")时),此方法有效.但是我找不到如何传递更复杂的论点.我尝试过

This works when I pass arguments without options, for instance when I put Test.Argument("plan"). But I was not able to find how to pass a more complex argument. I have tried

Tests.Argument("exclude integration")
Tests.Argument("exclude=integration")
Tests.Argument("-exclude integration")
Tests.Argument("-exclude=integration")
Tests.Argument("exclude", "integration")
Tests.Argument("exclude \"integration\"")

,甚至更多.仍然不知道正确的语法是什么.

and probably more. Still not any clue what is the correct syntax.

有人知道如何将带有选项的参数传递给sbt的specs2吗?

Does anyone know how to pass arguments with options to specs2 from sbt?

推荐答案

如果要传递多个参数,可以将多个字符串添加到一个Test.Argument

If you want to pass several arguments you can add several strings to one Test.Argument

testOptions in Test += Tests.Argument("include", "unit")

specs2 用户指南

There are examples of this in the specs2 User Guide here and in the Play documentation there.

这篇关于玩!框架:定制运行哪些测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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