DirtiesContext class final
Marks a test that leaves the application in a state that later tests must not see: the context is closed after the test, and the next test gets a new one.
One context serves all the tests of a class, which keeps them fast.
When a test changes the state of a bean (a counter, an in-memory store,
a cache), mark it. On a method it applies to that test; on the class,
to each of its tests; on a Nested field, to each test of the group.
After the restart the @Autowired() fields are set again with the new
beans. AfterEach methods run before the context is closed.
@Test()
@DirtiesContext() // the next test sees a counter at zero again
void counts() {
counter.increment();
expect(counter.value, 1);
}
Spring (Java): @DirtiesContext. On a class it means Spring's
classMode = AFTER_EACH_TEST_METHOD, not Spring's default
AFTER_CLASS: each test class has its own context, closed after its
tests anyway. In a test written as a function, call app.markDirty()
instead.
Constructors
- DirtiesContext()
-
Marks the test or the class.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited