SBT Tutorials
In this section, we will show how to use SBT to build, compile, run, test and package your Scala applications. So let's get started!
Install sbt:
sbt run:
sbt test:
- Run all tests in a Scala project using sbt
- Run only one specific test in a Scala project using sbt
- Run all the integration tests in a Scala project using sbt
- Run only a specific integration test in a Scala project using sbt
- Run a specific test class and a specific method
sbt debugging:
sbt resources:
- Show and list the unmanaged classpaths for your test module in a Scala project
- Show and list the unmanaged resource directories for your test module in a Scala project
Install sbt on Windows
To install sbt on Windows, download and run the Windows MSI from
http://www.scala-sbt.org/download.html
Install sbt on Mac
To install sbt on Mac, download and unpack the zip from
http://www.scala-sbt.org/download.html
Run a main class in a Scala project using sbt
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
Within the sbt shell, type in <Your Project Name>/run. For example, if your project is called HelloWorld, you would type in: HelloWorld/run
This would then display a list of classes which have main methods. You can then simply select the one you wish to run.
Run all the tests in a Scala project using sbt:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
To run all the tests in your Scala project using sbt, type the following command in the sbt shell: test
Run only one specific test in a Scala project using sbt:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
To run a specific test in your Scala project using sbt, type the following command in the sbt shell: testOnly com.yourpackage.YourTestClassName
Run all the integration tests in a Scala project using sbt:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
To run all the integration tests in your Scala project, type the following command in the sbt shell: it:test
NOTE: This assumes that you have an it folder under src
Run only a specific integration test in a Scala project using sbt:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
To run a specific integraiton test in your Scala project using sbt, type the following command in the sbt shell: it:test-only com.yourpackage.YourTest
Run a specific test class and a specific method:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
To run a specific test method from a specific test class in your Scala project, type the following command in the sbt shell: it:test-only com.yourpackage.YourTest -- -t "your test method name"
Run a main class or test class using sbt in a Scala project and analyze the stacktrace in IntelliJ:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
Run your main class or test class and if it crashes and produces a stacktrace, you can debug the stacktrace by copying the exception into IntelliJ -> select the Analyze menu -> select the Analyze stacktrace.
NOTE: You should now be able to click on the class names and navigate to the source for the class or method in IntelliJ.
Show and list the unmangedClasspaths for your test module in a Scala project:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
To list the unmanaged classpaths for your test module in a Scala project, type the following command in the sbt shell: show test:unmanagedClasspath
Show and list the unmanagedResourceDirectories for your test module in a Scala project:
From a command prompt, launch sbt at the root of your Scala project by typing in: sbt
To list the unmanaged unmanaged resource directories for your test module in a Scala project, type the following command in the sbt shell: show test:unmanagedResourceDirectories