【问题标题】:build.sbt it:test is not working for integration testing junit casesbuild.sbt it:test 不适用于集成测试 junit 案例
【发布时间】:2022-01-08 19:26:00
【问题描述】:

我是 scala 的新手, junit 测试用例没有在集成测试中运行。

文件夹结构

src
  |- it
  |- main
  |- test

当我执行sbt test 时,“test”文件夹中的所有测试用例都执行得很好, 但是当我这样做时it:test

[error] No such setting/task
[error] it:test
[error] 

it 文件夹包含 Tester.scala

        package RegexExtractor
        import org.junit.Assert.assertTrue
        import org.junit.Test
            
class  Tester   {
             @Test
     def testAdd1(): Unit = {
      val result = 2 + 4
      assertTrue(result == 6)
      System.out.println("Test final Passed")
     }
    }
    }

我在 build.sbt 中添加了

lazy val scalatest = "org.scalatest" %% "scalatest" % "3.0.5"
lazy val root = (project in file("."))
  .configs(IntegrationTest)
  .settings(
    Defaults.itSettings,
    libraryDependencies += scalatest % "it,test",

    // other settings here

  )

请帮我运行集成测试

【问题讨论】:

    标签: java scala junit sbt integration-testing


    【解决方案1】:

    在 SBT 中,junit-interface 提供了对 JUnit 的支持:

    libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.2" % Test
    

    junit-interface 添加到您的集成测试配置中:

    lazy val root = (project in file("."))
      .configs(IntegrationTest)
      .settings(
        Defaults.itSettings,
        libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.2" % "it,test"
      ...
      )
    

    Check some usage patterns for junit-interface.

    在您的情况下,it 运行所有集成测试:

    IntegrationTest/ test
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多