This user guide will help you get rolling quickly with ScalaTest. First a brief orientation:
Suite
, which represents a suite of tests.Suite
declares run
and other “lifecycle” methods that define a default way to write and run tests.Suite
and override lifecycle methods to support different testing styles.Suite
style and mixin traits.Suite
instances.To include ScalaTest in your sbt project, simply add this line:
libraryDependencies += "org.scalatest" % "scalatest_2.12" % "3.0.5" % "test"
To include ScalaTest in your Maven project, use:
<dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest_2.11</artifactId> <version>3.0.5</version> <scope>test</scope> </dependency>
For other ways to include ScalaTest in your project, see Running your tests.
Using ScalaTest on your project is as easy as 1, 2, 3:
The ScalaTest Maven plugin allows you to run ScalaTest tests through Maven without requiring @RunWith(classOf[JUnitRunner])
annotationsand access all functionality of the ScalaTest Runner
, including parallel execution and multiple reporters.
To use the ScalaTest Maven plugin, you need to disable SureFire and enable ScalaTest.Here's an example of how to do this in your pom.xml:
<!-- disable surefire -- > <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.7</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <!-- enable scalatest -- > <plugin> <groupId>org.scalatest</groupId> <artifactId>scalatest-maven-plugin</artifactId> <version>1.0</version> <configuration> <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> <junitxml>.</junitxml> <filereports>WDF TestSuite.txt</filereports> </configuration> <executions> <execution> <id>test</id> <goals> <goal>test</goal> </goals> </execution> </executions> </plugin>
The ScalaTest Maven plugin contains two "mojos". The test mojo is for "mvn test" commands, and the reporter mojo is for "mvn site" commands.Here are the configuration parameters.
Configuration options | |
---|---|
runpath | Comma separated list of additional elements to be addedto the ScalaTest runpath. project.build.outputDirectory andproject.build.testOutputDirectory are included by default |
suites | Comma separated list of suites to be executed |
tagsToInclude | Comma separated list of tags to include |
tagsToExclude | Comma separated list of tags to exclude |
config | Comma separated list of configuration parameters to pass to ScalaTest.The parameters must be of the format <key>=<value>: e.g., foo=bar,monkey=donkey |
parallel | Set to true to run suites in parallel |
membersOnlySuites | Comma separated list of packages containing suites to execute |
wildcardSuites | Comma separated list of wildcard suite names to execute |
testNGConfigFiles | Comma separated list of testNG xml files to execute |
jUnitClasses | Comma separated list of JUnit test class names to execute |
forkMode | Option to specify the forking mode. Can be "never" or "once". Surefire's "always" option, which wouldfork for each test-class, may be supported later. |
argLine | Option to specify additional JVM options to pass to the forked process. |
environmentVariables | Additional environment variables to pass to the forked process. |
systemProperties | Additional system properties to pass to the forked process. |
debugForkedProcess | Option to specify whether the forked process should wait at startup for a remote debugger to attach.If set to true , the forked process will suspend at startup and wait for a remotedebugger to attach to the configured port. |
debugArgLine | JVM options to pass to the forked process when debugForkedProcess is true. If set to a non-empty value, the standard debug arguments are replaced by the specified arguments. This allows customization of how remote debugging is done, without having to reconfigure the JVM options in argLine . |
debuggerPort | Port to listen on when debugging the forked process. The default value is 5005. |
forkedProcessTimeoutInSeconds | Timeout in seconds to allow the forked process to run before killing it and failing the test run.If set to 0, process never times out. The default value is 0. |
logForkedProcessCommand | Whether or not to log the command used to launch the forked process. The default value is false. |
reportsDirectory | (TestMojo only) Output directory in which ScalaTest file reports should be written to. Passed to ScalaTest via the -f argument. |
skipTests | (TestMojo only) Set to true to skip execution of tests. |
testFailureIgnore | (TestMojo only) Set to true to avoid failing the build when tests fail |
filereports | (TestMojo only) Comma separated list of filereporters. A filereporter consists of an optionalconfiguration and a mandatory filename, separated by whitespace: e.g., all.txt,XE ignored_and_pending.txt For more info on configuring reporters, see the scalatest documentation. |
reporters | (TestMojo only) Comma separated list of reporters. A reporter consist of an optional configurationand a mandatory reporter classname, separated by whitespace. The reporter classnamemust be the fully qualified name of a class extending org.scalatest.Reporter :e.g., C my.SuccessReporter,my.EverythingReporter For more info on configuring reporters, see the ScalaTest documentation. |
junitxml | (TestMojo only) Comma separated list of junitxml. A junitxml consists of a mandatory directory for the xml files.For more info on configuring reporters, see the scalatest documentation. |
stdout | (TestMojo only) Configuration for logging to stdout. (This logger is always enabled)For more info on configuring reporters, see the scalatest documentation. |
stderr | (TestMojo only) Configuration for logging to stderr. It is disabled by default, but will be enabledwhen configured. Empty configuration just means enable.For more info on configuring reporters, see the scalatest documentation. |
reportingOutputDirectory | (ReporterMojo only) Directory where reports will go. |
fileReporterOptions | (ReporterMojo only) Consists of an optional configuration parameters for the file reporter.For more info on configuring reporters, see the ScalaTest documentation. |
spanScaleFactor | Optional span scale factor, if not specified it will be 1.0. |