SpringBootTest class final

Marks a class whose tests run against the whole application: the application starts before the first test, and the class's @Autowired() fields are set from it.

Use it when a test needs the real wiring: a service with its repositories, properties bound from the config files, controllers behind MockMvc. The context starts once and all tests of the class share it (see DirtiesContext to restart it). A unit test that creates its objects by hand needs no annotation.

The annotation does nothing at run time. spring_core_dart_generator reads the class and writes test/spring/<name>.test.spring.dart, whose runSpringTests() declares the tests with springBootTest; the test file's main calls it. The other annotations of this file set the remaining options: ActiveProfiles, TestPropertySource, TestBean, Test and so on.

import 'spring/checkout.test.spring.dart'; // generated

// The shop starts with a test name; the test uses its real Checkout.
@SpringBootTest(args: ['--shop.name=Night Books'])
class CheckoutTest {
  @Autowired()
  late Checkout checkout;

  @Test()
  void paysThroughTheGateway() => expect(checkout.pay(3), isNotNull);
}

void main() => runSpringTests();

Spring (Java):

@SpringBootTest(args = "--shop.name=Night Books")
class CheckoutTest { ... }

Constructors

SpringBootTest({String? application, List<String> args = const [], Map<String, Object?> properties = const {}, List<String> resourceDirectories = const ['test/resources'], WebEnvironment webEnvironment = WebEnvironment.mock})
Every option has a default: @SpringBootTest() alone starts the package's only application, without arguments, with test/resources/ on the classpath and no web server.
const

Properties

application → String?
The entry point of the application to start, as a path in the package (bin/admin.dart, lib/main.dart).
final
args → List<String>
The command-line arguments the application starts with, such as --shop.name=Night Books. They win over the config files and the environment, not over properties. Empty by default.
final
hashCode → int
The hash code for this object.
no setterinherited
properties → Map<String, Object?>
Properties for the tests, which win over the config files, the environment and args (Spring's @SpringBootTest(properties = ...)).
final
resourceDirectories → List<String>
Directories put first on the classpath while the tests run, like src/test/resources in a Java project.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
webEnvironment → WebEnvironment
Which web server the tests get when the application uses spring_boot_starter_web.
final

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