scalasbt

What is the recommended way to setup integration test in sbt after the deprecation of custom configs


I have just stumble into this:

https://eed3si9n.com/sbt-drop-custom-config/

Specifically:

what about IntegrationTest?

IntegrationTest should be removed. It doesn’t add anything useful besides the fact that it hangs off a subproject.

So what is the recommended way to run Integration test? Should I create a subproject containing those tests? How can then be run separately from the other tests?


Solution

  • This worked for me:

    lazy val IntegrationTest = (project in file("integration"))
      .dependsOn(root % "provided -> provided;compile -> compile;test -> test; runtime -> runtime")
      .settings(
        publish / skip := true,
        // extra test dependencies
        libraryDependencies ++= Seq(
          "com.org" %% "integration_test_dep" % "1.0.0" % Test,
        ),
      )
    
    lazy val root = (project in file("."))
      .settings(name := "my-application")
    

    It specifies a separate module in folder integration and to run the integration tests, you can type:

    sbt IntegrationTest/test
    

    You additionally specify that it depends on the root module which contains the main code. We are also passing down all the dependencies in provided, compile, test and runtime scopes, so that you will need to add only the extra dependencies here. The integration module will be skipped in case of publish.