@TestPropertySource: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created blank page)
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=


* https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/testing.html#spring-testing-annotation-testpropertysource
=Internal=
* [[Spring_Framework_Testing_Concepts#Annotations|Spring Framework Testing Concepts]]
* [[@PropertySource]]
=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() {
      ...
    }
}