Class

org.scalatest.propspec

AnyPropSpec

Related Doc: package propspec

Permalink

class AnyPropSpec extends AnyPropSpecLike

A suite of property-based tests.

Recommended Usage: Class AnyPropSpec is a good fit for teams that want to write tests exclusively in terms of property checks, and is also a good choice for writing the occasional test matrix when a different style trait is chosen as the main unit testing style.

Here's an example AnyPropSpec:

package org.scalatest.examples.propspec

import org.scalatest._
import prop._
import scala.collection.immutable._

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks with Matchers {

  val examples =
    Table(
      "set",
      BitSet.empty,
      HashSet.empty[Int],
      TreeSet.empty[Int]
    )

  property("an empty Set should have size 0") {
    forAll(examples) { set =>
      set.size should be (0)
    }
  }

  property("invoking head on an empty set should produce NoSuchElementException") {
    forAll(examples) { set =>
      a [NoSuchElementException] should be thrownBy { set.head }
    }
  }
}

You can run a AnyPropSpec by invoking execute on it. This method, which prints test results to the standard output, is intended to serve as a convenient way to run tests from within the Scala interpreter. For example, to run SetSpec from within the Scala interpreter, you could write:

scala> org.scalatest.run(new SetSpec)

And you would see:

SetSpec:
- an empty Set should have size 0
- invoking head on an empty Set should produce NoSuchElementException

Or, to run just the “an empty Set should have size 0” method, you could pass that test's name, or any unique substring of the name, such as "size 0" or even just "0". Here's an example:

scala> org.scalatest.run(new SetSpec, "size 0")
SetSpec:
- an empty Set should have size 0

You can also pass to execute a config map of key-value pairs, which will be passed down into suites and tests, as well as other parameters that configure the run itself. For more information on running in the Scala interpreter, see the documentation for execute (below) and the ScalaTest shell.

The execute method invokes a run method that takes two parameters. This run method, which actually executes the suite, will usually be invoked by a test runner, such as run, tools.Runner, a build tool, or an IDE.

property” is a method, defined in AnyPropSpec, which will be invoked by the primary constructor of SetSpec. You specify the name of the test as a string between the parentheses, and the test code itself between curly braces. The test code is a function passed as a by-name parameter to property, which registers it for later execution.

A AnyPropSpec's lifecycle has two phases: the registration phase and the ready phase. It starts in registration phase and enters ready phase the first time run is called on it. It then remains in ready phase for the remainder of its lifetime.

Tests can only be registered with the property method while the AnyPropSpec is in its registration phase. Any attempt to register a test after the AnyPropSpec has entered its ready phase, i.e., after run has been invoked on the AnyPropSpec, will be met with a thrown TestRegistrationClosedException. The recommended style of using AnyPropSpec is to register tests during object construction as is done in all the examples shown here. If you keep to the recommended style, you should never see a TestRegistrationClosedException.

Ignored tests

To support the common use case of temporarily disabling a test, with the good intention of resurrecting the test at a later time, AnyPropSpec provides registration methods that start with ignore instead of property. Here's an example:

package org.scalatest.examples.suite.ignore

import org.scalatest._
import prop._
import scala.collection.immutable._

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks with Matchers {

  val examples =
    Table(
      "set",
      BitSet.empty,
      HashSet.empty[Int],
      TreeSet.empty[Int]
    )

  ignore("an empty Set should have size 0") {
    forAll(examples) { set =>
      set.size should be (0)
    }
  }

  property("invoking head on an empty set should produce NoSuchElementException") {
    forAll(examples) { set =>
      a [NoSuchElementException] should be thrownBy { set.head }
    }
  }
}

If you run this version of SetSuite with:

scala> org.scalatest.run(new SetSpec)

It will run only the second test and report that the first test was ignored:

SetSuite:
- an empty Set should have size 0 !!! IGNORED !!!
- invoking head on an empty Set should produce NoSuchElementException

Informers

One of the parameters to AnyPropSpec's run method is a Reporter, which will collect and report information about the running suite of tests. Information about suites and tests that were run, whether tests succeeded or failed, and tests that were ignored will be passed to the Reporter as the suite runs. Most often the reporting done by default by AnyPropSpec's methods will be sufficient, but occasionally you may wish to provide custom information to the Reporter from a test. For this purpose, an Informer that will forward information to the current Reporter is provided via the info parameterless method. You can pass the extra information to the Informer via its apply method. The Informer will then pass the information to the Reporter via an InfoProvided event. Here's an example that shows both a direct use as well as an indirect use through the methods of GivenWhenThen:

package org.scalatest.examples.propspec.info

import org.scalatest._
import prop._
import collection.mutable

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks with GivenWhenThen {

  val examples =
    Table(
      "set",
      mutable.BitSet.empty,
      mutable.HashSet.empty[Int],
      mutable.LinkedHashSet.empty[Int]
    )

  property("an element can be added to an empty mutable Set") {

    forAll(examples) { set =>

      info("----------------")

      Given("an empty mutable " + set.getClass.getSimpleName)
      assert(set.isEmpty)

      When("an element is added")
      set += 99

      Then("the Set should have size 1")
      assert(set.size === 1)

      And("the Set should contain the added element")
      assert(set.contains(99))
    }
  }
}

If you run this AnyPropSpec from the interpreter, you will see the following output:

scala> org.scalatest.run(new SetSpec)
SetSpec:
- an element can be added to an empty mutable Set
  + ----------------
  + Given an empty mutable BitSet
  + When an element is added
  + Then the Set should have size 1
  + And the Set should contain the added element
  + ----------------
  + Given an empty mutable HashSet
  + When an element is added
  + Then the Set should have size 1
  + And the Set should contain the added element
  + ----------------
  + Given an empty mutable LinkedHashSet
  + When an element is added
  + Then the Set should have size 1
  + And the Set should contain the added element

Documenters

AnyPropSpec also provides a markup method that returns a Documenter, which allows you to send to the Reporter text formatted in Markdown syntax. You can pass the extra information to the Documenter via its apply method. The Documenter will then pass the information to the Reporter via an MarkupProvided event.

Here's an example AnyPropSpec that uses markup:

package org.scalatest.examples.propspec.markup

import org.scalatest._
import prop._
import collection.mutable

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks with GivenWhenThen {

  markup { """

Mutable Set
-----------

A set is a collection that contains no duplicate elements.

To implement a concrete mutable set, you need to provide implementations
of the following methods:

    def contains(elem: A): Boolean
    def iterator: Iterator[A]
    def += (elem: A): this.type
    def -= (elem: A): this.type

If you wish that methods like `take`,
`drop`, `filter` return the same kind of set,
you should also override:

    def empty: This

It is also good idea to override methods `foreach` and
`size` for efficiency.

  """ }

  val examples =
    Table(
      "set",
      mutable.BitSet.empty,
      mutable.HashSet.empty[Int],
      mutable.LinkedHashSet.empty[Int]
    )

  property("an element can be added to an empty mutable Set") {

    forAll(examples) { set =>

      info("----------------")

      Given("an empty mutable " + set.getClass.getSimpleName)
      assert(set.isEmpty)

      When("an element is added")
      set += 99

      Then("the Set should have size 1")
      assert(set.size === 1)

      And("the Set should contain the added element")
      assert(set.contains(99))
    }

    markup("This test finished with a **bold** statement!")
  }
}

Although all of ScalaTest's built-in reporters will display the markup text in some form, the HTML reporter will format the markup information into HTML. Thus, the main purpose of markup is to add nicely formatted text to HTML reports. Here's what the above SetSpec would look like in the HTML reporter:

Notifiers and alerters

ScalaTest records text passed to info and markup during tests, and sends the recorded text in the recordedEvents field of test completion events like TestSucceeded and TestFailed. This allows string reporters (like the standard out reporter) to show info and markup text after the test name in a color determined by the outcome of the test. For example, if the test fails, string reporters will show the info and markup text in red. If a test succeeds, string reporters will show the info and markup text in green. While this approach helps the readability of reports, it means that you can't use info to get status updates from long running tests.

To get immediate (i.e., non-recorded) notifications from tests, you can use note (a Notifier) and alert (an Alerter). Here's an example showing the differences:

package org.scalatest.examples.propspec.note

import org.scalatest._
import prop._
import collection.mutable

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks {

  val examples =
    Table(
      "set",
      mutable.BitSet.empty,
      mutable.HashSet.empty[Int],
      mutable.LinkedHashSet.empty[Int]
    )

  property("an element can be added to an empty mutable Set") {

    info("info is recorded")
    markup("markup is *also* recorded")
    note("notes are sent immediately")
    alert("alerts are also sent immediately")

    forAll(examples) { set =>

      assert(set.isEmpty)
      set += 99
      assert(set.size === 1)
      assert(set.contains(99))
    }
  }
}

Because note and alert information is sent immediately, it will appear before the test name in string reporters, and its color will be unrelated to the ultimate outcome of the test: note text will always appear in green, alert text will always appear in yellow. Here's an example:

scala> org.scalatest.run(new SetSpec)
SetSpec:
  + notes are sent immediately
  + alerts are also sent immediately
- an element can be added to an empty mutable Set
  + info is recorded
  + markup is *also* recorded

Another example is slowpoke notifications. If you find a test is taking a long time to complete, but you're not sure which test, you can enable slowpoke notifications. ScalaTest will use an Alerter to fire an event whenever a test has been running longer than a specified amount of time.

In summary, use info and markup for text that should form part of the specification output. Use note and alert to send status notifications. (Because the HTML reporter is intended to produce a readable, printable specification, info and markup text will appear in the HTML report, but note and alert text will not.)

Pending tests

A pending test is one that has been given a name but is not yet implemented. The purpose of pending tests is to facilitate a style of testing in which documentation of behavior is sketched out before tests are written to verify that behavior (and often, before the behavior of the system being tested is itself implemented). Such sketches form a kind of specification of what tests and functionality to implement later.

To support this style of testing, a test can be given a name that specifies one bit of behavior required by the system being tested. The test can also include some code that sends more information about the behavior to the reporter when the tests run. At the end of the test, it can call method pending, which will cause it to complete abruptly with TestPendingException.

Because tests in ScalaTest can be designated as pending with TestPendingException, both the test name and any information sent to the reporter when running the test can appear in the report of a test run. (The code of a pending test is executed just like any other test.) However, because the test completes abruptly with TestPendingException, the test will be reported as pending, to indicate the actual test, and possibly the functionality, has not yet been implemented.

You can mark tests pending in AnyPropSpec like this:

import org.scalatest._
import prop._
import scala.collection.immutable._

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks with Matchers {

  val examples =
    Table(
      "set",
      BitSet.empty,
      HashSet.empty[Int],
      TreeSet.empty[Int]
    )

  property("an empty Set should have size 0") (pending)

  property("invoking head on an empty set should produce NoSuchElementException") {
    forAll(examples) { set =>
      a [NoSuchElementException] should be thrownBy { set.head }
    }
  }
}

(Note: "(pending)" is the body of the test. Thus the test contains just one statement, an invocation of the pending method, which throws TestPendingException.) If you run this version of SetSuite with:

scala> org.scalatest.run(new SetSuite)

It will run both tests, but report that first test is pending. You'll see:

SetSuite:
- An empty Set should have size 0 (pending)
- Invoking head on an empty Set should produce NoSuchElementException

One difference between an ignored test and a pending one is that an ignored test is intended to be used during a significant refactorings of the code under test, when tests break and you don't want to spend the time to fix all of them immediately. You can mark some of those broken tests as ignored temporarily, so that you can focus the red bar on just failing tests you actually want to fix immediately. Later you can go back and fix the ignored tests. In other words, by ignoring some failing tests temporarily, you can more easily notice failed tests that you actually want to fix. By contrast, a pending test is intended to be used before a test and/or the code under test is written. Pending indicates you've decided to write a test for a bit of behavior, but either you haven't written the test yet, or have only written part of it, or perhaps you've written the test but don't want to implement the behavior it tests until after you've implemented a different bit of behavior you realized you need first. Thus ignored tests are designed to facilitate refactoring of existing code whereas pending tests are designed to facilitate the creation of new code.

One other difference between ignored and pending tests is that ignored tests are implemented as a test tag that is excluded by default. Thus an ignored test is never executed. By contrast, a pending test is implemented as a test that throws TestPendingException (which is what calling the pending method does). Thus the body of pending tests are executed up until they throw TestPendingException. The reason for this difference is that it enables your unfinished test to send InfoProvided messages to the reporter before it completes abruptly with TestPendingException, as shown in the previous example on Informers that used the GivenWhenThen trait.

Tagging tests

A AnyPropSpec's tests may be classified into groups by tagging them with string names. As with any suite, when executing a AnyPropSpec, groups of tests can optionally be included and/or excluded. To tag a AnyPropSpec's tests, you pass objects that extend class org.scalatest.Tag to methods that register tests. Class Tag takes one parameter, a string name. If you have created tag annotation interfaces as described in the Tag documentation, then you will probably want to use tag names on your test functions that match. To do so, simply pass the fully qualified names of the tag interfaces to the Tag constructor. For example, if you've defined a tag annotation interface with fully qualified names, com.mycompany.tags.DbTest, then you could create a matching tag for AnyPropSpecs like this:

package org.scalatest.examples.propspec.tagging

import org.scalatest.Tag

object DbTest extends Tag("com.mycompany.tags.DbTest")

Given these definitions, you could place AnyPropSpec tests into groups with tags like this:

import org.scalatest._
import prop._
import tagobjects.Slow
import scala.collection.immutable._

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks with Matchers {

  val examples =
    Table(
      "set",
      BitSet.empty,
      HashSet.empty[Int],
      TreeSet.empty[Int]
    )

  property("an empty Set should have size 0", Slow) {
    forAll(examples) { set =>
      set.size should be (0)
    }
  }

  property("invoking head on an empty set should produce NoSuchElementException",
      Slow, DbTest) {

    forAll(examples) { set =>
      a [NoSuchElementException] should be thrownBy { set.head }
    }
  }
}

This code marks both tests with the org.scalatest.tags.Slow tag, and the second test with the com.mycompany.tags.DbTest tag.

The run method takes a Filter, whose constructor takes an optional Set[String] called tagsToInclude and a Set[String] called tagsToExclude. If tagsToInclude is None, all tests will be run except those those belonging to tags listed in the tagsToExclude Set. If tagsToInclude is defined, only tests belonging to tags mentioned in the tagsToInclude set, and not mentioned in tagsToExclude, will be run.

Shared fixtures

A test fixture is composed of the objects and other artifacts (files, sockets, database connections, etc.) tests use to do their work. When multiple tests need to work with the same fixtures, it is important to try and avoid duplicating the fixture code across those tests. The more code duplication you have in your tests, the greater drag the tests will have on refactoring the actual production code.

ScalaTest recommends three techniques to eliminate such code duplication:

Each technique is geared towards helping you reduce code duplication without introducing instance vars, shared mutable objects, or other dependencies between tests. Eliminating shared mutable state across tests will make your test code easier to reason about and more amenable for parallel test execution.

The techniques in AnyPropSpec are identical to those in FunSuite, but with “test” replaced by “property”. The following table summarizes the options with a link to the relevant documentation for trait FunSuite:

Refactor using Scala when different tests need different fixtures.
get-fixture methods The extract method refactor helps you create a fresh instances of mutable fixture objects in each test that needs them, but doesn't help you clean them up when you're done.
fixture-context objects By placing fixture methods and fields into traits, you can easily give each test just the newly created fixtures it needs by mixing together traits. Use this technique when you need different combinations of mutable fixture objects in different tests, and don't need to clean up after.
loan-fixture methods Factor out dupicate code with the loan pattern when different tests need different fixtures that must be cleaned up afterwards.
Override withFixture when most or all tests need the same fixture.
withFixture(NoArgTest) The recommended default approach when most or all tests need the same fixture treatment. This general technique allows you, for example, to perform side effects at the beginning and end of all or most tests, transform the outcome of tests, retry tests, make decisions based on test names, tags, or other test data. Use this technique unless:
Different tests need different fixtures (refactor using Scala instead)
An exception in fixture code should abort the suite, not fail the test (use a before-and-after trait instead)
You have objects to pass into tests (override withFixture(OneArgTest) instead)
withFixture(OneArgTest) Use when you want to pass the same fixture object or objects as a parameter into all or most tests.
Mix in a before-and-after trait when you want an aborted suite, not a failed test, if the fixture code fails.
BeforeAndAfter Use this boilerplate-buster when you need to perform the same side-effects before and/or after tests, rather than at the beginning or end of tests.
BeforeAndAfterEach Use when you want to stack traits that perform the same side-effects before and/or after tests, rather than at the beginning or end of tests.

Using AnyPropSpec to implement a test matrix

Using fixture-context objects in a AnyPropSpec is a good way to implement a test matrix. What is the matrix? A test matrix is a series of tests that you need to run on a series of subjects. For example, The Scala API contains many implementations of trait Set. Every implementation must obey the contract of Set. One property of any Set is that an empty Set should have size 0, another is that invoking head on an empty Set should give you a NoSuchElementException, and so on. Already you have a matrix, where rows are the properties and the columns are the set implementations:

 BitSetHashSetTreeSet
An empty Set should have size 0passpasspass
Invoking head on an empty set should produce NoSuchElementExceptionpasspasspass

One way to implement this test matrix is to define a trait to represent the columns (in this case, BitSet, HashSet, and TreeSet) as elements in a single-dimensional Table. Each element in the Table represents one Set implementation. Because different properties may require different fixture instances for those implementations, you can define a trait to hold the examples, like this:

trait SetExamples extends Tables {

  def examples = Table("set", bitSet, hashSet, treeSet)

  def bitSet: BitSet
  def hashSet: HashSet[Int]
  def treeSet: TreeSet[Int]
}

Given this trait, you could provide empty sets in one implementation of SetExamples, and non-empty sets in another. Here's how you might provide empty set examples:

class EmptySetExamples extends SetExamples {
  def bitSet = BitSet.empty
  def hashSet = HashSet.empty[Int]
  def treeSet = TreeSet.empty[Int]
}

And here's how you might provide set examples with one item each:

class SetWithOneItemExamples extends SetExamples {
  def bitSet = BitSet(1)
  def hashSet = HashSet(1)
  def treeSet = TreeSet(1)
}

Armed with these example classes, you can define checks of properties that require empty or non-empty set fixtures by using instances of these classes as fixture-context objects. In other words, the columns of the test matrix are implemented as elements of a one-dimensional table of fixtures, the rows are implemented as property clauses of a AnyPropSpec.

Here's a complete example that checks the two properties mentioned previously:

package org.scalatest.examples.propspec.matrix

import org.scalatest._
import org.scalatest.prop._
import scala.collection.immutable._

trait SetExamples extends Tables {

  def examples = Table("set", bitSet, hashSet, treeSet)

  def bitSet: BitSet
  def hashSet: HashSet[Int]
  def treeSet: TreeSet[Int]
}

class EmptySetExamples extends SetExamples {
  def bitSet = BitSet.empty
  def hashSet = HashSet.empty[Int]
  def treeSet = TreeSet.empty[Int]
}

class SetSpec extends propspec.AnyPropSpec with TableDrivenPropertyChecks with Matchers {

  property("an empty Set should have size 0") {
    new EmptySetExamples {
      forAll(examples) { set =>
        set.size should be (0)
      }
    }
  }

  property("invoking head on an empty set should produce NoSuchElementException") {
    new EmptySetExamples {
      forAll(examples) { set =>
        a [NoSuchElementException] should be thrownBy { set.head }
      }
    }
  }
}

One benefit of this approach is that the compiler will help you when you need to add either a new row or column to the matrix. In either case, you'll need to ensure all cells are checked to get your code to compile.

Shared tests

Sometimes you may want to run the same test code on different fixture objects. That is to say, you may want to write tests that are "shared" by different fixture objects. You accomplish this in a AnyPropSpec in the same way you would do it in a FunSuite, except instead of test you say property, and instead of testsFor you say propertiesFor. For more information, see the Shared tests section of FunSuite's documentation.

Annotations
@Finders()
Linear Supertypes
AnyPropSpecLike, Documenting, Alerting, Notifying, Informing, TestRegistration, TestSuite, Suite, Serializable, Serializable, Assertions, TripleEquals, TripleEqualsSupport, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AnyPropSpec
  2. AnyPropSpecLike
  3. Documenting
  4. Alerting
  5. Notifying
  6. Informing
  7. TestRegistration
  8. TestSuite
  9. Suite
  10. Serializable
  11. Serializable
  12. Assertions
  13. TripleEquals
  14. TripleEqualsSupport
  15. AnyRef
  16. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new AnyPropSpec()

    Permalink

Type Members

  1. class CheckingEqualizer[L] extends AnyRef

    Permalink
    Definition Classes
    TripleEqualsSupport
  2. class Equalizer[L] extends AnyRef

    Permalink
    Definition Classes
    TripleEqualsSupport
  3. trait NoArgTest extends () ⇒ Outcome with TestData

    Permalink
    Attributes
    protected
    Definition Classes
    TestSuite

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. def !==[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

    Permalink
    Definition Classes
    TripleEqualsSupport
  3. def !==(right: Null): TripleEqualsInvocation[Null]

    Permalink
    Definition Classes
    TripleEqualsSupport
  4. def !==[T](right: T): TripleEqualsInvocation[T]

    Permalink
    Definition Classes
    TripleEqualsSupport
  5. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  6. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  7. def ===[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

    Permalink
    Definition Classes
    TripleEqualsSupport
  8. def ===(right: Null): TripleEqualsInvocation[Null]

    Permalink
    Definition Classes
    TripleEqualsSupport
  9. def ===[T](right: T): TripleEqualsInvocation[T]

    Permalink
    Definition Classes
    TripleEqualsSupport
  10. def alert: Alerter

    Permalink

    Returns an Alerter that during test execution will forward strings (and other objects) passed to its apply method to the current reporter.

    Returns an Alerter that during test execution will forward strings (and other objects) passed to its apply method to the current reporter. If invoked in a constructor, it will register the passed string for forwarding later during test execution. If invoked while this AnyPropSpec is being executed, such as from inside a test function, it will forward the information to the current reporter immediately. If invoked at any other time, it will print to the standard output. This method can be called safely by any thread.

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike → Alerting
  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. macro def assert(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  13. macro def assert(condition: Boolean)(implicit prettifier: Prettifier, pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  14. macro def assertCompiles(code: String)(implicit pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  15. macro def assertDoesNotCompile(code: String)(implicit pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  16. def assertResult(expected: Any)(actual: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  17. def assertResult(expected: Any, clue: Any)(actual: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  18. def assertThrows[T <: AnyRef](f: ⇒ Any)(implicit classTag: ClassTag[T], pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  19. macro def assertTypeError(code: String)(implicit pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  20. macro def assume(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  21. macro def assume(condition: Boolean)(implicit prettifier: Prettifier, pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  22. def cancel(cause: Throwable)(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  23. def cancel(message: String, cause: Throwable)(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  24. def cancel(message: String)(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  25. def cancel()(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  26. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. def convertEquivalenceToAToBConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: <:<[A, B]): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
  28. def convertEquivalenceToBToAConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: <:<[B, A]): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
  29. def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
  30. implicit def convertToEqualizer[T](left: T): Equalizer[T]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
  31. def defaultEquality[A]: Equality[A]

    Permalink
    Definition Classes
    TripleEqualsSupport
  32. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  33. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  34. def expectedTestCount(filter: Filter): Int

    Permalink
    Definition Classes
    Suite
  35. def fail(cause: Throwable)(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  36. def fail(message: String, cause: Throwable)(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  37. def fail(message: String)(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  38. def fail()(implicit pos: Position): Nothing

    Permalink
    Definition Classes
    Assertions
  39. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  40. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  41. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  42. def ignore(testName: String, testTags: Tag*)(testFun: ⇒ Any)(implicit pos: Position): Unit

    Permalink

    Register a property-based test to ignore, which has the specified name, optional tags, and function value that takes no arguments.

    Register a property-based test to ignore, which has the specified name, optional tags, and function value that takes no arguments. This method will register the test for later ignoring via an invocation of one of the run methods. This method exists to make it easy to ignore an existing test by changing the call to test to ignore without deleting or commenting out the actual test code. The test will not be run, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this AnyPropSpec instance.

    testName

    the name of the test

    testTags

    the optional list of tags for this test

    testFun

    the test function

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike
    Exceptions thrown

    DuplicateTestNameException if a test with the same name has been registered previously

    NotAllowedException if testName had been registered previously

    TestRegistrationClosedException if invoked after run has been invoked on this suite

  43. def info: Informer

    Permalink

    Returns an Informer that during test execution will forward strings passed to its apply method to the current reporter.

    Returns an Informer that during test execution will forward strings passed to its apply method to the current reporter. If invoked in a constructor, it will register the passed string for forwarding later during test execution. If invoked from inside a scope, it will forward the information to the current reporter immediately. If invoked from inside a test function, it will record the information and forward it to the current reporter only after the test completed, as recordedEvents of the test completed event, such as TestSucceeded. If invoked at any other time, it will print to the standard output. This method can be called safely by any thread.

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike → Informing
  44. def intercept[T <: AnyRef](f: ⇒ Any)(implicit classTag: ClassTag[T], pos: Position): T

    Permalink
    Definition Classes
    Assertions
  45. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  46. def lowPriorityTypeCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], ev: <:<[A, B]): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
  47. def markup: Documenter

    Permalink

    Returns a Documenter that during test execution will forward strings passed to its apply method to the current reporter.

    Returns a Documenter that during test execution will forward strings passed to its apply method to the current reporter. If invoked in a constructor, it will register the passed string for forwarding later during test execution. If invoked from inside a scope, it will forward the information to the current reporter immediately. If invoked from inside a test function, it will record the information and forward it to the current reporter only after the test completed, as recordedEvents of the test completed event, such as TestSucceeded. If invoked at any other time, it will print to the standard output. This method can be called safely by any thread.

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike → Documenting
  48. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  49. def nestedSuites: IndexedSeq[Suite]

    Permalink
    Definition Classes
    Suite
  50. def note: Notifier

    Permalink

    Returns a Notifier that during test execution will forward strings (and other objects) passed to its apply method to the current reporter.

    Returns a Notifier that during test execution will forward strings (and other objects) passed to its apply method to the current reporter. If invoked in a constructor, it will register the passed string for forwarding later during test execution. If invoked while this AnyPropSpec is being executed, such as from inside a test function, it will forward the information to the current reporter immediately. If invoked at any other time, it will print to the standard output. This method can be called safely by any thread.

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike → Notifying
  51. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  52. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  53. def pending: Assertion with PendingStatement

    Permalink
    Definition Classes
    Assertions
  54. def pendingUntilFixed(f: ⇒ Unit)(implicit pos: Position): Assertion with PendingStatement

    Permalink
    Definition Classes
    Assertions
  55. def propertiesFor(unit: Unit): Unit

    Permalink

    Registers shared tests.

    Registers shared tests.

    This method enables the following syntax for shared tests in a AnyPropSpec:

    propertiesFor(nonEmptyStack(lastValuePushed))
    

    This method just provides syntax sugar intended to make the intent of the code clearer. Because the parameter passed to it is type Unit, the expression will be evaluated before being passed, which is sufficient to register the shared tests. For examples of shared tests, see the Shared tests section in the main documentation for this trait.

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike
  56. def property(testName: String, testTags: Tag*)(testFun: ⇒ Any)(implicit pos: Position): Unit

    Permalink

    Register a property-based test with the specified name, optional tags, and function value that takes no arguments.

    Register a property-based test with the specified name, optional tags, and function value that takes no arguments. This method will register the test for later execution via an invocation of one of the run methods. The passed test name must not have been registered previously on this AnyPropSpec instance.

    testName

    the name of the property

    testTags

    the optional list of tags for this property

    testFun

    the property function

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike
    Exceptions thrown

    DuplicateTestNameException if a test with the same name has been registered previously

    NotAllowedException if testName had been registered previously

    NullArgumentException if testName or any passed test tag is null

    TestRegistrationClosedException if invoked after run has been invoked on this suite

  57. final def registerIgnoredTest(testText: String, testTags: Tag*)(testFun: ⇒ Any)(implicit pos: Position): Unit

    Permalink
    Definition Classes
    AnyPropSpecLike → TestRegistration
  58. final def registerTest(testText: String, testTags: Tag*)(testFun: ⇒ Any)(implicit pos: Position): Unit

    Permalink
    Definition Classes
    AnyPropSpecLike → TestRegistration
  59. def rerunner: Option[String]

    Permalink
    Definition Classes
    Suite
  60. def run(testName: Option[String], args: Args): Status

    Permalink
    Definition Classes
    AnyPropSpecLike → Suite
  61. def runNestedSuites(args: Args): Status

    Permalink
    Attributes
    protected
    Definition Classes
    Suite
  62. def runTest(testName: String, args: Args): Status

    Permalink

    Run a test.

    Run a test. This trait's implementation runs the test registered with the name specified by testName.

    testName

    the name of one test to run.

    args

    the Args for this run

    returns

    a Status object that indicates when the test started by this method has completed, and whether or not it failed .

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike → TestSuite → Suite
    Exceptions thrown

    IllegalArgumentException if testName is defined but a test with that name does not exist on this AnyPropSpec

    NullArgumentException if any of testName, reporter, stopper, or configMap is null.

  63. def runTests(testName: Option[String], args: Args): Status

    Permalink

    Run zero to many of this AnyPropSpec's tests.

    Run zero to many of this AnyPropSpec's tests.

    testName

    an optional name of one test to run. If None, all relevant tests should be run. I.e., None acts like a wildcard that means run all relevant tests in this Suite.

    args

    the Args for this run

    returns

    a Status object that indicates when all tests started by this method have completed, and whether or not a failure occurred.

    Attributes
    protected
    Definition Classes
    AnyPropSpecLike → Suite
    Exceptions thrown

    IllegalArgumentException if testName is defined, but no test with the specified test name exists in this Suite

    NullArgumentException if any of the passed parameters is null.

  64. final val succeed: Assertion

    Permalink
    Definition Classes
    Assertions
  65. def suiteId: String

    Permalink
    Definition Classes
    Suite
  66. def suiteName: String

    Permalink
    Definition Classes
    Suite
  67. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  68. def tags: Map[String, Set[String]]

    Permalink

    A Map whose keys are String names of tagged tests and whose associated values are the Set of tags for the test.

    A Map whose keys are String names of tagged tests and whose associated values are the Set of tags for the test. If this AnyPropSpec contains no tags, this method returns an empty Map.

    This trait's implementation returns tags that were passed as strings contained in Tag objects passed to methods property and ignore.

    In addition, this trait's implementation will also auto-tag tests with class level annotations. For example, if you annotate @Ignore at the class level, all test methods in the class will be auto-annotated with org.scalatest.Ignore.

    Definition Classes
    AnyPropSpecLike → Suite
  69. def testDataFor(testName: String, theConfigMap: ConfigMap = ConfigMap.empty): TestData

    Permalink
    Definition Classes
    AnyPropSpecLike → Suite
  70. def testNames: Set[String]

    Permalink

    An immutable Set of test names.

    An immutable Set of test names. If this AnyPropSpec contains no tests, this method returns an empty Set.

    This trait's implementation of this method will return a set that contains the names of all registered tests. The set's iterator will return those names in the order in which the tests were registered.

    Definition Classes
    AnyPropSpecLike → Suite
  71. def toString(): String

    Permalink

    Returns a user friendly string for this suite, composed of the simple name of the class (possibly simplified further by removing dollar signs if added by the Scala interpeter) and, if this suite contains nested suites, the result of invoking toString on each of the nested suites, separated by commas and surrounded by parentheses.

    Returns a user friendly string for this suite, composed of the simple name of the class (possibly simplified further by removing dollar signs if added by the Scala interpeter) and, if this suite contains nested suites, the result of invoking toString on each of the nested suites, separated by commas and surrounded by parentheses.

    returns

    a user-friendly string for this suite

    Definition Classes
    AnyPropSpec → AnyRef → Any
  72. def typeCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], ev: <:<[B, A]): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
  73. implicit def unconstrainedEquality[A, B](implicit equalityOfA: Equality[A]): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
  74. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  75. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  76. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  77. def withClue[T](clue: Any)(fun: ⇒ T): T

    Permalink
    Definition Classes
    Assertions
  78. def withFixture(test: NoArgTest): Outcome

    Permalink
    Attributes
    protected
    Definition Classes
    TestSuite

Deprecated Value Members

  1. def conversionCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], cnv: (B) ⇒ A): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The conversionCheckedConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  2. def convertEquivalenceToAToBConversionConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: (A) ⇒ B): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The convertEquivalenceToAToBConversionConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  3. def convertEquivalenceToBToAConversionConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: (B) ⇒ A): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The convertEquivalenceToBToAConversionConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  4. def lowPriorityConversionCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], cnv: (A) ⇒ B): CanEqual[A, B]

    Permalink
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The lowPriorityConversionCheckedConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  5. final val styleName: String

    Permalink

    The styleName lifecycle method has been deprecated and will be removed in a future version of ScalaTest.

    The styleName lifecycle method has been deprecated and will be removed in a future version of ScalaTest.

    This method was used to support the chosen styles feature, which was deactivated in 3.1.0. The internal modularization of ScalaTest in 3.2.0 will replace chosen styles as the tool to encourage consistency across a project. We do not plan a replacement for styleName.

    Definition Classes
    AnyPropSpecLike → Suite
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The styleName lifecycle method has been deprecated and will be removed in a future version of ScalaTest with no replacement.

Inherited from AnyPropSpecLike

Inherited from Documenting

Inherited from Alerting

Inherited from Notifying

Inherited from Informing

Inherited from TestRegistration

Inherited from TestSuite

Inherited from Suite

Inherited from Serializable

Inherited from Serializable

Inherited from Assertions

Inherited from TripleEquals

Inherited from TripleEqualsSupport

Inherited from AnyRef

Inherited from Any

Ungrouped