【问题标题】:Run only one package test cases scala只运行一个包测试用例 scala
【发布时间】:2020-09-05 14:36:57
【问题描述】:

我的包结构为:


    src ->  test -> scala -> notification

在通知里面我有两个包单元和集成。

unit 包有单元测试,而集成包有集成测试。我只想执行单元测试用例。有没有办法我只能通过 sbt 测试来做到这一点?

对于一个班级,我知道可以这样做: 我试过一节课,但不知道怎么做。

sbt "test:testOnly *LoginServiceSpec"

【问题讨论】:

    标签: scala sbt scalatest


    【解决方案1】:

    testOnly 允许您使用*run wildcards。因此,如果您所有的测试都在包命名空间x 中,您可以调用

    > testOnly x.*
    

    这个通配符可以放在任何地方,所以如果你在x 中有一个子包,但你所有的测试都以例如结尾。 Spec 你可以跑

    > testOnly x.*Spec
    

    但是,如果您使用集成测试,我建议他们使用 creating a separate configuration,以便您可以运行:

    > test
    

    用于单元测试和

    > it:test
    

    用于集成测试。然后你会把它们放在src/it/scala。目录。

    【讨论】:

    • 是 src/it/scala 还是 src/main/it/scala?我添加了库依赖 "org.scalatest" %% "scalatest" % 3.0.0 % "it,test" 我有它,比如 src/it/resources 和 src/it/scala
    • 你可以运行show it:sourceDirectoriesshow it:sourceDirectory,你会看到哪个被sbt使用。
    • 我已经添加了库依赖 "org.scalatest" %% "scalatest" % 3.0.0 % "it,test" 我有它像 src/it/resources 和 src/it/scala 我我得到没有这样的设置/任务
    • 然后使用这条指令scala-sbt.org/1.x/docs/Testing.html#Integration+Tests - 你必须先设置它测试。
    • 我已经这样做了:lazy val root = (project in file(".")) .configs(IntegrationTest) .settings(commonSettings) .settings( Defaults.itSettings, libraryDependencies ++= Seq( ... ) )
    【解决方案2】:

    试试这个

    sbt "test:testOnly notification.unit.*"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-10
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多