当前位置: 首页 > 工具软件 > ScalaTest > 使用案例 >

ScalaTest and Maven plugin settings

萧宣
2023-12-01

This user guide will help you get rolling quickly with ScalaTest. First a brief orientation:

  • The central concept in ScalaTest is the suite, a collection of zero to many tests.
  • A test can be anything with a name that can start and either succeed, fail, be pending, or canceled.
  • The central unit of composition in ScalaTest is Suite, which represents a suite of tests.
  • Trait Suite declares run and other “lifecycle” methods that define a default way to write and run tests.
  • These lifecycle methods can be overridden to customize how tests are written and run.
  • ScalaTest offers style traits that extend Suite and override lifecycle methods to support different testing styles.
  • It provides mixin traits that override lifecycle methods of the style traits to address particular testing needs.
  • You define test classes by composing Suite style and mixin traits.
  • You define test suites by composing 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:

  1. Select your testing styles
  2. Define your base classes
  3. Start writing tests
 

Using the ScalaTest Maven plugin

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.

  • group id: org.scalatest
  • artifact id: scalatest-maven-plugin
  • version: 1.0

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
runpathComma separated list of additional elements to be addedto the ScalaTest runpath. project.build.outputDirectory andproject.build.testOutputDirectory are included by default
suitesComma separated list of suites to be executed
tagsToIncludeComma separated list of tags to include
tagsToExcludeComma separated list of tags to exclude
configComma separated list of configuration parameters to pass to ScalaTest.The parameters must be of the format <key>=<value>: e.g., foo=bar,monkey=donkey
parallelSet to true to run suites in parallel
membersOnlySuitesComma separated list of packages containing suites to execute
wildcardSuitesComma separated list of wildcard suite names to execute
testNGConfigFilesComma separated list of testNG xml files to execute
jUnitClassesComma separated list of JUnit test class names to execute
forkModeOption to specify the forking mode. Can be "never" or "once". Surefire's "always" option, which wouldfork for each test-class, may be supported later.
argLineOption to specify additional JVM options to pass to the forked process.
environmentVariablesAdditional environment variables to pass to the forked process.
systemPropertiesAdditional system properties to pass to the forked process.
debugForkedProcessOption 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.
debugArgLineJVM 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.
debuggerPortPort to listen on when debugging the forked process. The default value is 5005.
forkedProcessTimeoutInSecondsTimeout 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.
logForkedProcessCommandWhether 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.txtFor 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.EverythingReporterFor 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.
spanScaleFactorOptional span scale factor, if not specified it will be 1.0.
 类似资料:

相关阅读

相关文章

相关问答