How do you share classes between test configurations using SBT

Related searches

I have followed the instructions on SBT's documentation for setting up test configurations. I have three test configurations Test, IntegrationTest, and AcceptanceTest. So my src directory looks like this:

  • src/
    • acceptance/
      • scala/
    • it/
      • scala/
    • test/
      • scala/

My question is, how can I configure SBT to allow sharing of classes between these configurations? Example: I have a class in the "it" configuration for simplifying database setup and tear down. One of my acceptance tests in the "acceptance" configuration could make use of this class. How do I make that "it" class available to the test in "acceptance"

Many thanks in advance.

A configuration can extend another configuration to use that configuration's dependencies and classes. For example, the custom test configuration section shows this definition for the custom configuration:

lazy val FunTest = config("fun") extend(Test)

The extend part means that the compiled normal test sources will be on the classpath for fun sources. In your case, declare the acceptance configuration to extend the it configuration:

lazy val AcceptanceTest = config("acceptance") extend(IntegrationTest)

sbt Reference Manual — Testing, The resources may be accessed from tests by using the getResource methods of java.lang. Test is the configuration and means that ScalaCheck will only be on the test classpath and it isn't If you want to only run test classes whose name ends with “Test”, use Tests. Additional test configurations with shared sources. SBT. To use SBT, you must configure your build.sbt file to link against the Databricks Connect JARs instead of the usual Spark library dependency. You do this with the unmanagedBase directive in the following example build file, which assumes a Scala app that has a com.example.Test main object: build.sbt

In case you want to stick with predefined configurations instead of defining new ones, and since both Test and IntegrationTest extend Runtime (one would expect IntegrationTest to extend Test…), you could use the following:

dependencyClasspath in IntegrationTest := (dependencyClasspath in IntegrationTest).value ++ (exportedProducts in Test).value

This should put all the classes you define in Test on the IntegrationTest classpth.

test:dependencyClasspath ordering question � Issue #2904 � sbt/sbt , This behavior makes it very difficult to share test configuration across projects. The project classpath, in this case test-classes always appears before the Maybe it's potentially possible, but from sbt's perspective we use� .NET Core provides a clean configuration system and in ASP.NET Core that code is automatically configured for you. In test and other non-Web projects however you have to manually configure the configuration provider yourself. In this post I look at a couple of ways to set up a configuration provider both using raw configuration objects or by explicitly configuring through the depedency

An approach is documented here:

Chapter 5. Testing - sbt in Action, Configuring your build to use specs2; Learning how to run JUnit tests; Incorporating We'll show you how to configure each framework separately. To generate the reports, you'll have to fork your tests to run them in a different JVM from sbt. It does this by creating Scala files and then compiling and loading the classes. To check the Service class, we need to have an instance of Service class created and available as a @Bean so that we can @Autowire it in our test class. This configuration is achieved by using the @TestConfiguration annotation.

SBT uses the Maven default directory layout.

It will recognize folders unders src/test/scala to compile along with src/main/scala.

So, if you move the other folders under src/test/scala SBT will compile them and you can share code between them. e.g.:

└── scala
    ├── acceptance
    │   └── scala
    │       └── Acceptance.scala
    ├── it
    │   └── scala
    │       └── IT.scala
    └── Test.scala

Running sbt test will compile all three files in the directory. So, with this Acceptance refer to and can create a new IT class for example.

Run, debug and test Scala - Help, To access the dialog, select Run | Edit Configurations from the main menu. You can run your Scala code through IntelliJ IDEA, use sbt shell, or use Open a class in the editor, for which you want to create a test and place� But SBT is supported for day-to-day development since it can provide much faster iterative compilation. More advanced developers may wish to use SBT. The SBT build is derived from the Maven POM files, and so the same Maven profiles and variables can be set to control the SBT build. For example:

Apache Kudu Integration Testing in Scala/SBT Applications, Share This Post. Share on This post describes how to configure a Scala application using SBT in order to use the Kudu testing utilities. The class under test is instantiated with the KuduClient from the test harness. Layout of /src should be obvious for everyone who ever worked on projects with Maven-ish directory structure.We have 2 directories here, /src/main and /src/test, which in turn group source code by languages (so Java files would be under /java subdirectory, Scala files within /scala, etc) and resources that are in resources directory (there are exceptions like Android build configuration, but

SBT. To use SBT, you must configure your build.sbt file to link against the Databricks Connect JARs instead of the usual Spark library dependency. You do this with the unmanagedBase directive in the following example build file, which assumes a Scala app that has a com.example.Test main object:

The active solution configuration has been changed to Test with the active solution platform set to x64. Choose Close . You can quickly verify or change the active solution configuration by using the Solution Configurations list on the Standard toolbar.

  • Ahh... This is much simpler. Thank you!
  • but they will also be run as Tests and compiled, so you need to have identical classpath
  • Doesn't seem to work for me. AcceptanceTest cannot find classes from IntegrationTest. Has anything changed since?
  • updated link to sbt docs on custom test configurations
  • One note about this. This solution didn't work for my VSCode/Metals integration (although sbt compiled it fine). I found a fix here:
  • last time when I posted an url without good example, It was minus'd remorselessly :)
  • Is this the only way? I do like the separation provided by having different configurations. I have it structured this way so sbt test will run unit tests, sbt it:test will run integration tests, and sbt acceptance:test will run acceptances tests. No other way to get it classes on acceptances class path?
  • No, I don't think this is the only way. You would have to add the custom source paths and classpaths to the build. Adding scalaSource in Test := file("src/acceptance/scala") and scalaSource in Test := file("src/it/scala") in the build.sbt file will get these paths to be compiled when test is ran.
  • Brilliant! This does exactly what I want. Thank you.
  • Well this definitely put me down the right path. This is what ultimately did the trick for me: unmanagedSourceDirectories in AcceptanceTest <++= baseDirectory { base => Seq( base / "src/acceptance/scala", base / "src/it/scala.scala" ) }
  • How is AcceptanceTest defined?