Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package scalatest

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    Definition Classes
    org
  • trait Suite extends Assertions with AbstractSuite with Serializable

    A suite of tests.

    A suite of tests. A Suite instance encapsulates a conceptual suite (i.e., a collection) of tests.

    This trait provides an interface composed of "lifecycle methods" that allow suites of tests to be run. Its implementation enables a default way of writing and executing tests. Subtraits and subclasses can override Suite's lifecycle methods to enable other ways of writing and executing tests.

    Prior to ScalaTest 2.0.M4, trait Suite served two purposes: 1) It served as the base class of ScalaTest's family of style traits, and 2) It was itself a style trait in which tests are methods. Although it will continue to serve its first purpose, it has been deprecated as a style trait. Pre-existing code that used Suite as a style trait to define tests as methods will continue to work during the deprecation period, but will generate a deprecation warning. Please change all such uses of Suite to use trait Spec instead.

    Nested suites

    A Suite can refer to a collection of other Suites, which are called nested Suites. Those nested Suites can in turn have their own nested Suites, and so on. Large test suites can be organized, therefore, as a tree of nested Suites. This trait's run method, in addition to invoking its test methods, invokes run on each of its nested Suites.

    A List of a Suite's nested Suites can be obtained by invoking its nestedSuites method. If you wish to create a Suite that serves as a container for nested Suites, whether or not it has test methods of its own, simply override nestedSuites to return a List of the nested Suites. Because this is a common use case, ScalaTest provides a convenience Suites class, which takes a variable number of nested Suites as constructor parameters. Here's an example:

    package org.scalatest.examples.suite.nested
    
    import org.scalatest._
    
    class ASuite extends FunSuite {
      test("A should have ASCII value 41 hex") {
        assert('A' === 0x41)
      }
      test("a should have ASCII value 61 hex") {
        assert('a' === 0x61)
      }
    }
    class BSuite extends FunSuite {
      test("B should have ASCII value 42 hex") {
        assert('B' === 0x42)
      }
      test("b should have ASCII value 62 hex") {
        assert('b' === 0x62)
      }
    }
    class CSuite extends FunSuite {
      test("C should have ASCII value 43 hex") {
        assert('C' === 0x43)
      }
      test("c should have ASCII value 63 hex") {
        assert('c' === 0x63)
      }
    }
    
    class ASCIISuite extends Suites(
      new ASuite,
      new BSuite,
      new CSuite
    )
    

    If you now run ASCIISuite:

    scala> new ASCIISuite execute
    

    You will see reports printed to the standard output that indicate the nested suites—ASuite, BSuite, and CSuite—were run:

    ASCIISuite:
    ASuite:
    - A should have ASCII value 41 hex
    - a should have ASCII value 61 hex
    BSuite:
    - B should have ASCII value 42 hex
    - b should have ASCII value 62 hex
    CSuite:
    - C should have ASCII value 43 hex
    - c should have ASCII value 63 hex
    

    Note that Runner can discover Suites automatically, so you need not necessarily define nested Suites explicitly. See the documentation for Runner for more information.

    The config map

    In some cases you may need to pass information to a suite of tests. For example, perhaps a suite of tests needs to grab information from a file, and you want to be able to specify a different filename during different runs. You can accomplish this in ScalaTest by passing the filename in a config map of key-value pairs, which is passed to run as a ConfigMap. The values in the config map are called "config objects," because they can be used to configure suites, reporters, and tests.

    You can specify a string config object is via the ScalaTest Runner, either via the command line or ScalaTest's ant task. (See the documentation for Runner for information on how to specify config objects on the command line.) The config map is passed to run, runNestedSuites, runTests, and runTest, so one way to access it in your suite is to override one of those methods. If you need to use the config map inside your tests, you can access it from the NoArgTest passed to withFixture, or the OneArgTest passed to withFixture in the traits in the org.scalatest.fixture package. (See the documentation for fixture.Suite for instructions on how to access the config map in tests.)

    Executing suites in parallel

    The run method takes as one of its parameters an optional Distributor. If a Distributor is passed in, this trait's implementation of run puts its nested Suites into the distributor rather than executing them directly. The caller of run is responsible for ensuring that some entity runs the Suites placed into the distributor. The -P command line parameter to Runner, for example, will cause Suites put into the Distributor to be run in parallel via a pool of threads. If you wish to execute the tests themselves in parallel, mix in ParallelTestExecution.

    Treatment of java.lang.Errors

    The Javadoc documentation for java.lang.Error states:

    An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.

    Because Errors are used to denote serious errors, trait Suite and its subtypes in the ScalaTest API do not always treat a test that completes abruptly with an Error as a test failure, but sometimes as an indication that serious problems have arisen that should cause the run to abort. For example, if a test completes abruptly with an OutOfMemoryError, it will not be reported as a test failure, but will instead cause the run to abort. Because not everyone uses Errors only to represent serious problems, however, ScalaTest only behaves this way for the following exception types (and their subclasses):

    • java.lang.annotation.AnnotationFormatError
    • java.awt.AWTError
    • java.nio.charset.CoderMalfunctionError
    • javax.xml.parsers.FactoryConfigurationError
    • java.lang.LinkageError
    • java.lang.ThreadDeath
    • javax.xml.transform.TransformerFactoryConfigurationError
    • java.lang.VirtualMachineError

    The previous list includes all Errors that exist as part of Java 1.5 API, excluding java.lang.AssertionError. ScalaTest does treat a thrown AssertionError as an indication of a test failure. In addition, any other Error that is not an instance of a type mentioned in the previous list will be caught by the Suite traits in the ScalaTest API and reported as the cause of a test failure.

    Although trait Suite and all its subtypes in the ScalaTest API consistently behave this way with regard to Errors, this behavior is not required by the contract of Suite. Subclasses and subtraits that you define, for example, may treat all Errors as test failures, or indicate errors in some other way that has nothing to do with exceptions.

    Extensibility

    Trait Suite provides default implementations of its methods that should be sufficient for most applications, but many methods can be overridden when desired. Here's a summary of the methods that are intended to be overridden:

    • run - override this method to define custom ways to run suites of tests.
    • runNestedSuites - override this method to define custom ways to run nested suites.
    • runTests - override this method to define custom ways to run a suite's tests.
    • runTest - override this method to define custom ways to run a single named test.
    • testNames - override this method to specify the Suite's test names in a custom way.
    • tags - override this method to specify the Suite's test tags in a custom way.
    • nestedSuites - override this method to specify the Suite's nested Suites in a custom way.
    • suiteName - override this method to specify the Suite's name in a custom way.
    • expectedTestCount - override this method to count this Suite's expected tests in a custom way.

    For example, this trait's implementation of testNames performs reflection to discover methods starting with test, and places these in a Set whose iterator returns the names in alphabetical order. If you wish to run tests in a different order in a particular Suite, perhaps because a test named testAlpha can only succeed after a test named testBeta has run, you can override testNames so that it returns a Set whose iterator returns testBeta before testAlpha. (This trait's implementation of run will invoke tests in the order they come out of the testNames Set iterator.)

    Alternatively, you may not like starting your test methods with test, and prefer using @Test annotations in the style of Java's JUnit 4 or TestNG. If so, you can override testNames to discover tests using either of these two APIs @Test annotations, or one of your own invention. (This is in fact how org.scalatest.junit.JUnitSuite and org.scalatest.testng.TestNGSuite work.)

    Moreover, test in ScalaTest does not necessarily mean test method. A test can be anything that can be given a name, that starts and either succeeds or fails, and can be ignored. In org.scalatest.FunSuite, for example, tests are represented as function values. This approach might look foreign to JUnit users, but may feel more natural to programmers with a functional programming background. To facilitate this style of writing tests, FunSuite overrides testNames, runTest, and run such that you can define tests as function values.

    You can also model existing JUnit 3, JUnit 4, or TestNG tests as suites of tests, thereby incorporating tests written in Java into a ScalaTest suite. The "wrapper" classes in packages org.scalatest.junit and org.scalatest.testng exist to make this easy. No matter what legacy tests you may have, it is likely you can create or use an existing Suite subclass that allows you to model those tests as ScalaTest suites and tests and incorporate them into a ScalaTest suite. You can then write new tests in Scala and continue supporting older tests in Java.

    Definition Classes
    scalatest
  • AssertionsHelper
  • CheckingEqualizer
  • Equalizer
  • LegacyCheckingEqualizer
  • LegacyEqualizer
  • NoArgTest
t

org.scalatest.Suite

NoArgTest

trait NoArgTest extends () ⇒ Outcome with TestData

A test function taking no arguments and returning an Outcome.

For more detail and examples, see the relevant section in the documentation for trait fixture.FlatSpec.

Attributes
protected
Source
Suite.scala
Linear Supertypes
TestData, () ⇒ Outcome, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. NoArgTest
  2. TestData
  3. Function0
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def apply(): Outcome

    Runs the body of the test, returning an Outcome.

    Runs the body of the test, returning an Outcome.

    Definition Classes
    NoArgTest → Function0
  2. abstract val configMap: ConfigMap

    A ConfigMap containing objects that can be used to configure the fixture and test.

    A ConfigMap containing objects that can be used to configure the fixture and test.

    Definition Classes
    TestData
  3. abstract val name: String

    The name of this test.

    The name of this test.

    See the main documentation for this trait for an explanation of the difference between name, text, and scopes.

    Definition Classes
    TestData
  4. abstract val scopes: IndexedSeq[String]

    An immutable IndexedSeq containing the text for any "scopes" enclosing this test, in order from outermost to innermost scope.

    An immutable IndexedSeq containing the text for any "scopes" enclosing this test, in order from outermost to innermost scope.

    See the main documentation for this trait for an explanation of the difference between name, text, and scopes. If a test has no surrounding scopes, this field will contain an empty IndexedSeq.

    Definition Classes
    TestData
  5. abstract val tags: Set[String]

    Tag names for this test.

    Tag names for this test.

    Definition Classes
    TestData
  6. abstract val text: String

    The "text" for this test.

    The "text" for this test.

    See the main documentation for this trait for an explanation of the difference between name, text, and scopes. If a test has no surrounding scopes, this field will contain the same string as name.

    Definition Classes
    TestData

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  16. def toString(): String
    Definition Classes
    Function0 → AnyRef → Any
  17. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from TestData

Inherited from () ⇒ Outcome

Inherited from AnyRef

Inherited from Any

Ungrouped