SpringBootTestContext class final

The handle on the application that springBootTest started: its beans, its environment, what it printed and the port of its server.

springBootTest returns it at once, before the context exists; the context starts in setUpAll. So use it inside tests, setUp, or a setUpAll declared after the springBootTest call. In a test class, an @Autowired() late SpringBootTestContext app; field receives it.

final app = springBootTest(springApplication);

test('a new basket is empty', () {
  // The application's real Basket bean.
  expect(app.getBean<Basket>().items, isEmpty);
});

Properties

args → List<String>
The command-line arguments the application starts with.
final
context → ConfigurableApplicationContext
The running application context, for what the shortcuts of this class do not cover.
no setter
environment → ConfigurableEnvironment
The context's environment, to read a property as the application sees it.
no setter
hashCode → int
The hash code for this object.
no setterinherited
localServerPort → int
The port the real server listens on, read from the local.server.port property: use it to build URLs for clients that need a socket.
no setter
mockMvc → MockMvc
Sends requests to the application's controllers in memory, through the dispatcher a real server would use.
no setter
output → List<String>
The lines the application printed, such as the failure report of a context that did not start, over all the starts of this test file. Each line is also shown when a test fails. The startup information is logged through SpringLog and is not here; captureLogs records logs.
no setter
resourceDirectories → List<String>
The classpath directories of the tests: the resourceDirectories of springBootTest, resolved against the test package, first one first.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
webEnvironment → WebEnvironment
The web server the tests asked for.
final

Methods

findBean<T extends Object>({String? qualifier}) → T?
The bean of type T (with qualifier, the one it names), or null when there is none: what an optional @Autowired() field (late Mailer? mailer;) receives.
getBean<T extends Object>({String? qualifier}) → T
The bean of type T; with qualifier, the one it names among several. Throws when no bean matches.
getBeanByName(String name) → Object
The bean called name (or an alias of it), whatever its type. Throws when there is none.
getBeans<T extends Object>({String? qualifier}) → List<T>
Every bean of type T (with qualifier, only those it selects), sorted by @Order: what an @Autowired() List<T> field receives.
markDirty() → void
Closes the context at the end of the current test, so the next test starts a new one (Spring's @DirtiesContext).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
optionalValue<T>(String expression) → T?
Like value, but null when a placeholder has no value: what a nullable @Value field receives.
toString() → String
A string representation of this object.
inherited
value<T>(String expression) → T
Resolves a @Value expression as a bean's @Value field would: ${...} placeholders first, then #{...} expressions, converted to T. What a @Value field of a test class receives.

Operators

operator ==(Object other) → bool
The equality operator.
inherited