TestPropertySource class final
Adds properties for the test class's application, written inline or
read from .properties files.
Use it for settings only the tests need, such as a smaller limit or the URL of a local fake, without creating a test profile. Both kinds win over the config files, the environment and the command line; properties win over locations. A file that does not exist fails the start of the context.
// A bigger basket than in production, plus the settings of a file.
@SpringBootTest()
@TestPropertySource(
locations: ['resources:big-shop.properties'], // test/resources/
properties: {'shop.max-basket-size': 100},
)
class BasketTest { ... }
Spring (Java):
@SpringBootTest
@TestPropertySource(
locations = "resources:big-shop.properties",
properties = "shop.max-basket-size=100")
class BasketTest { ... }
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
locations
→ List<
String> -
Resource locations of
.propertiesfiles, such asresources:big-shop.properties(found intest/resources/first). When two files set the same key, the later file wins.final -
properties
→ Map<
String, Object?> -
Inline properties. They are merged with the
propertiesof SpringBootTest; on the same key, these win.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