Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing test classes into Scala console in sbt?

Tags:

I am building a Scala project in the standard directory layout using sbt. I want to run sbt console and import my unit tests so that I can play with them in the Scala REPL. What is the easiest way to do this? Is there a command I can pass to sbt, or something I can add to build.sbt?

Note that I don't necessarily want to run unit tests from the sbt console. (Though that would be nice too.) Instead a have test fixtures that set up data structures that I want to use in my REPL session.

like image 896
W.P. McNeill Avatar asked Jun 10 '13 19:06

W.P. McNeill


People also ask

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.

Does sbt run tests in parallel?

By default, sbt executes tasks in parallel (subject to the ordering constraints already described) in an effort to utilize all available processors. Also by default, each test class is mapped to its own task to enable executing tests in parallel.

Does sbt test compile?

We have a build. sbt file that is used for multiple projects. Doing sbt test:compile compiled the tests for every single project and took over 30 minutes.


1 Answers

Use test configuration scope, like this:

sbt> test:console 

For more information, see Scopes in the sbt documentation.

With specs2 for example, you can go:

sbt> test:console  console> import mytestpackage._ console> import org.specs2._ console> specs2.run(new MySpec) 
like image 51
Eric Avatar answered Oct 10 '22 03:10

Eric