【问题标题】:How to prevent sbt from running integration tests?如何防止 sbt 运行集成测试?
【发布时间】:2012-12-02 09:47:37
【问题描述】:

Maven surefire-plugin 不运行集成测试(按照惯例,它们以“IT”后缀命名),但 sbt 同时运行:单元和集成。那么,如何防止这种行为呢?有没有一种通用的方法来区分 ScalaTest 的集成和单元测试(默认情况下不运行 FeatureSpec-tests)

【问题讨论】:

    标签: junit sbt scalatest


    【解决方案1】:

    如何做到这一点在http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing#additional-test-configurations-with-shared-sources 的 sbt 手册中有详细记录:

    //Build.scala
    import sbt._
    import Keys._
    
    object B extends Build {
      lazy val root =
        Project("root", file("."))
          .configs( FunTest )
          .settings( inConfig(FunTest)(Defaults.testTasks) : _*)
          .settings(
             libraryDependencies += specs,
             testOptions in Test := Seq(Tests.Filter(itFilter)),
             testOptions in FunTest := Seq(Tests.Filter(unitFilter))
             )
    
      def itFilter(name: String): Boolean = name endsWith "ITest"
      def unitFilter(name: String): Boolean = (name endsWith "Test") && !itFilter(name)
    
      lazy val FunTest = config("fun") extend(Test)
      lazy val specs = "org.scala-tools.testing" %% "specs" % "1.6.8" % "test"
    }
    

    调用sbt test 进行单元测试,调用sbt fun:test 进行集成测试,调用sbt test fun:test 进行两者。

    【讨论】:

      【解决方案2】:

      最新的 sbt 最简单的方法就是应用 IntegrationTest 配置和相应的设置,如 here 所述, - 并将测试放在项目的 src/it/scala 目录中。

      【讨论】:

        猜你喜欢
        • 2021-10-15
        • 2021-10-24
        • 1970-01-01
        • 2011-02-02
        • 2023-03-12
        • 2014-03-29
        • 1970-01-01
        • 1970-01-01
        • 2012-06-18
        相关资源
        最近更新 更多