How to run and compile exact one test in sbt?

sbt run single integration test
sbt test not running tests
sbt scalatest tags
sbt run specific test method
scalatest only run one test
scalatest run single test intellij
sbt test failed
sbt test fork

I'm working on a legacy project that has been written in Scala using SBT. The unit tests have been written with ScalaTest. The problem is there is a lot of test classes that have compilation error.

I want to run only one of these test classes and I know for running only one test I should try something like this:

test:testOnly *myClass

But when I run this command, the SBT will try to compile the whole project and as I said, there's a lot of test classes that have compilation error. Is there any way to tell SBT exactly which classes need to be compiled and so the others will be ignored?


sbt (software), It runs all of the tests. The correct way of running a single test class looks like this: 1, sbt "testOnly  To speed up your edit-compile-test cycle, you can ask sbt to automatically recompile or run tests whenever you save a source file. Make a command run when one or more source files change by prefixing the command with ~. For example, in sbt shell try:


Consider defining a single-argument custom command in build.sbt like so

commands += Command.single("compileAndTestOnly") { (state, file) =>
  s"""set sources in Test := (sources in Test).value.filter(_.name.contains("$file"))""" ::
    "test" :: state
}

Now run it with compileAndTestOnly MySpec.scala. This command modifies Test \ sources setting to contain only a single file like so

sources in Test := (sources in Test).value.filter(_.name.contains(file))

Note sources in Compile is left untouched. Afterwards it executes test which in effect compiles and runs a single test.

This answer is inspired by 0__.

How to run a single test in SBT, 1. add this to your project file: Just add this to your sbt build: To see classpath that sbt uses to lookup for test classes, you can use the following command: The -oD argument above will be pass to ScalaTest for all test runs, you can In unformatted mode, you can see exactly what is happening when it is happening. The tests that were not run before The tests that have one or more transitive dependencies, maybe in a different project, recompiled. Tab completion . Tab completion is provided for test names based on the results of the last test:compile. This means that a new sources aren’t available for tab completion until they are compiled and deleted


It's impossible to instruct sbt to only compile the file that contains the test that matches your name, because it'll only know what name the test has after it's compiled -- in scala a class name and a file name don't have to have anything to do with another.

A source filter is not built-in in sbt. You will need a custom task along the lines of what @mario-galic has above.

Beware though, that will filter based on file name, not on class name.

I agree it would be a neat feature for sbt to run all tests it can even when the compilation of some files were to fail.

Using ScalaTest with sbt, Here's how to do that with sbt and ScalaTest. Run specific test suites by passing them as arguments to testOnly : definition from /my/blah/project [info] Set current project to blah (in build file:/my/blah/) [blah] $ testOnly **. $ sbt > compile > run > package. You can run multiple commands at one time, such as running clean before compile: > clean compile Common SBT commands. At the time of this writing, there are 247 SBT commands available (which I just found out by hitting the Tab key at the SBT shell prompt, which triggered SBT’s tab completion).


TIL: run specific tests with `sbt testOnly` « Serge Gebhardt (sgeb.io), You call higher-order RDD methods and pass functions that specify the exact For simplicity sake, you assume that the words are separated by a single space. You can also use it to run your tests. sbt is a powerful build tool; mastering it  This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.9, “Specifying a Main Class to Run with SBT.” Problem. In a Scala SBT project, you have multiple main methods in objects in your project, and you want to specify which main method should be run when you type sbt run, or specify the main method that should be invoked when your project is


Big Data Analytics with Spark: A Practitioner's Guide to Using , Setup Simple Build Tool (hereafter called SBT) is a build tool specifically used SBT runs and compiles Java and Scala files and uses the Maven directory structure. developer is able to be expressive and describe the exact intent of the test. When you run a task like compile, it runs on the current project. So you don’t necessarily have to compile the root project, you could compile only a subproject. You can run a task in another project by explicitly specifying the project ID, such as subProjectID/compile. Common code . The definitions in .sbt files are not visible in other .sbt


1. Setup - Testing in Scala [Book], The sbt plugin sbtScalaNative is used inside Scala Native exactly as it is used in You can run only the test of interest by using one of the following commands:. The main class is passed the arguments provided. Please see Running Project Code for details on the use of System.exit and multithreading (including GUIs) in code run by this action. test:run runs a main class in the test code. runMain <main-class> <argument>* Runs the specified main class for the project in the same virtual machine as sbt. The