简体   繁体   中英

build.sbt it:test is not working for integration testing junit cases

I am new to scala, junit test cases are not running in integration test.

folder structure

src
  |- it
  |- main
  |- test

when i do sbt test all the test cases in "test" folder is executed fine, but when i do it:test

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

where it folder contain 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")
     }
    }
    }

i added in 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

  )

Please help me for running integration test

In SBT support for JUnit is provided by junit-interface :

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

Add junit-interface to your integration test configuration:

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 .

In your case for it to run all integration test:

IntegrationTest/ test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM