TestData
A bundle of information about the current test.
A TestData object is passed to the withFixture methods of traits Suite and FixtureSuite (both NoArgTest and OneArgTest extend TestData) and to the beforeEach and afterEach methods of trait BeforeAndAfterEach. This enables fixtures and tests to make use of the test name and configuration objects in the config map.
In ScalaTest's event model, a test may be surrounded by “scopes.” Each test and scope is associated with string of text. A test's name is a concatenation of the text of any surrounding scopes followed by the text provided with the test itself, after each text element has been trimmed and one space inserted between each component. Here's an example:
package org.scalatest.examples.freespec
import org.scalatest.FreeSpec
class SetSpec extends FreeSpec {
"A Set" - {
"when empty" - {
"should have size 0" in {
assert(Set.empty.size === 0)
}
"should produce NoSuchElementException when head is invoked" in {
assertThrows[NoSuchElementException] {
Set.empty.head
}
}
}
}
}
The above FreeSpec contains two tests, both nested inside the same two scopes. The outermost scope names the subject, A Set. The nested scope qualifies the subject with when empty. Inside that scope are the two tests. The text of the tests are:
-
should have size 0 -
should produce NoSuchElementException when head is invoked
Therefore, the names of these two tests are:
-
A Stack when empty should have size 0 -
A Stack when empty should produce NoSuchElementException when head is invoked
The TestData instance for the first test would contain:
-
name:"A Stack when empty should have size 0" -
scopes:collection.immutable.IndexedSeq("A Stack", "when empty") -
text:"should have size 0"
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes