@TestPropertySource: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
=Internal= | =Internal= | ||
* [[Spring_Framework_Testing_Concepts#Annotations|Spring Framework Testing Concepts]] | |||
* [[@PropertySource]] | |||
=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]], 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() {
...
}
}