Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you share classes between test configurations using SBT

Tags:

scala

sbt

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.

like image 608
Brian Scaturro Avatar asked Nov 14 '12 20:11

Brian Scaturro


People also ask

Does sbt run tests in parallel?

sbt maps each test class to a task. sbt runs tasks in parallel and within the same JVM by default.

What is ScalaTest sbt?

ScalaTest is one of the main testing libraries for Scala projects, and in this lesson you'll see how to create a Scala project that uses ScalaTest. You'll also be able to compile, test, and run the project with sbt.

How do I clear my sbt cache?

You can use Pretty Clean to clean the all of dev tools caches including SBT. PrettyClean also cleans the SBT project's target folder.

How do I run a Scala test?

Run Scala tests with coverageOpen your project. Open the test in question in the editor. icon and select the Run 'name' with Coverage option.


2 Answers

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)
like image 61
Mark Harrah Avatar answered Sep 18 '22 08:09

Mark Harrah


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.

##EDIT:

I was just became aware to amuch better solution thanks to @mjhoy:

lazy val DeepIntegrationTest = IntegrationTest.extend(Test)
like image 44
gilad hoch Avatar answered Sep 20 '22 08:09

gilad hoch