@TestPropertySource: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 10: | Line 10: | ||
=Overview= | =Overview= | ||
Test property sources have higher precedence than those loaded from the operating system’s environment or Java system properties as well as property sources added by the application declaratively through [[@PropertySource]] or | Test property sources have higher precedence than those loaded from the operating system’s environment or Java system properties as well as property sources added by the application declaratively through [[@PropertySource]], programmatically or via [[@ConfigurationProperties]]. This is the recommended way to test behavior that depends on a specific system property value (or a set of system property values). | ||
<syntaxhighlight lang='java'> | |||
@RunWith(SpringRunner.class) | |||
... | |||
@TestPropertySource(properties = { "some.multi.level.property = 1", "some.other.multi.level.property = 2"}) | |||
public class ... { | |||
@Test | |||
public void someTest() { | |||
... | |||
} | |||
} | |||
</syntaxhighlight> |
Latest revision as of 23:09, 13 December 2018
External
Internal
Overview
Test property sources have higher precedence than those loaded from the operating system’s environment or Java system properties as well as property sources added by the application declaratively through @PropertySource, programmatically or via @ConfigurationProperties. This is the recommended way to test behavior that depends on a specific system property value (or a set of system property values).
@RunWith(SpringRunner.class)
...
@TestPropertySource(properties = { "some.multi.level.property = 1", "some.other.multi.level.property = 2"})
public class ... {
@Test
public void someTest() {
...
}
}