DataTestSetup class final
What makes a test context the slice of a @DataTest: the data beans of
an application and the starter's auto-configuration, an in-memory
database, and nothing else.
It gives springBootTest two things for the application it describes:
properties, which leave out the auto-configuration of the other
starters, and an initializer, which leaves out the application's other
beans (DataTestSlice) and replaces its databases (TestDatabase). The
generated code of a @DataTest class does it; in a test written as
functions, do it by hand, and wrap each test in runInTestTransaction:
void main() {
final data = DataTestSetup(springApplication);
final app = springBootTest(
springApplication,
properties: data.properties,
initializers: [data.initializer],
);
test('saves a book', () => runInTestTransaction(app.context, () async {
await app.getBean<BookRepository>().save(Book(title: 'Dune'));
}));
}
Spring (Java): the annotations of @DataJdbcTest:
@TypeExcludeFilters, @AutoConfigureDataJdbc,
@AutoConfigureTestDatabase and @Transactional.
Constructors
-
DataTestSetup(SpringApplication application, {List<
Type> include = const [], bool replaceDatabase = true}) -
The slice of
application: its data beans, those of the types ininclude, and the databases replaced unlessreplaceDatabaseis false.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
include
→ List<
Type> -
The beans added to the slice by the types of their classes.
final
- initializer → ApplicationContextInitializer
-
The initializer of the slice, for
springBootTest(initializers:): it replaces the databases and leaves out the beans, in each context the test starts.no setter -
properties
→ Map<
String, Object?> -
The properties of the slice:
spring.autoconfigure.excludenames the auto-configuration modules of the application that are not autoConfigurationNames (the web, cache, security... starters).no setter - replaceDatabase → bool
-
Whether the databases of the properties are replaced.
final
- 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
Static Properties
-
autoConfigurationNames
→ List<
String> -
The names of the auto-configuration modules a slice keeps: the core
one, logging and the data starter's own.
no setter