scalacheck

How to use ScalaCheck in the SBT REPL (command line) alvin January 4, 2017 - 11:15am

If you add ScalaCheck to an SBT project like this:

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.4" % "test"

it’s only available in the SBT “test” scope. This means that when you start a Scala REPL session inside of SBT with its console command, the ScalaCheck library won’t be available in that scope.

To use ScalaCheck with the SBT console (REPL), don’t use its console command — use test:console instead. A complete example looks like this:

$ sbt

> test:console

scala> import org.scalacheck.Gen.choose

Note that after you type test:console your project may be compiled, so that step may take a few moments.

In summary, use SBT’s console command to start a “normal” Scala REPL inside SBT, and use test:console to start a REPL that you can run tests inside of. (Note that this same advice also applies to using ScalaTest or specs2.)

How to compile, run, and package a Scala project with SBT

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.2, “How to compile, run, and package a Scala project with SBT.”

Back to top

Problem

You want to use SBT to compile and run a Scala project, and package the project as a JAR file.

Back to top

Solution

Create a directory layout to match what SBT expects, then run sbt compile to compile your project, sbt run to run your project, and sbt package to package your project as a JAR file.

Table of Contents

  1. Problem
  2. Solution
Back to top

ScalaCheck: Property-based testing for Scala

ScalaCheck: Property-based testing for Scala

ScalaCheck is a library written in Scala and used for automated property-based testing of Scala or Java programs. ScalaCheck was originally inspired by the Haskell library QuickCheck, but has also ventured into its own.

ScalaCheck has no external dependencies other than the Scala runtime, and works great with sbt, the Scala build tool. It is also fully integrated in the test frameworks ScalaTest and specs2. You can of course also use ScalaCheck completely standalone, with its built-in test runner.

ScalaCheck: Automated specification-based testing of Scala applications

ScalaCheck is a library written in the Scala Programming Language and is used for automated specification-based testing of Scala or Java software applications. ScalaCheck was originally inspired by the Haskell library QuickCheck, but has also ventured into its own.

ScalaCheck has no dependencies other than the Scala runtime, and is supported by SBT, ScalaTest and Specs2. You can of course also use ScalaCheck completely standalone, with its built-in test runner.