Showing posts with the label @TestPropertySource

Spring Testing Annotation - @TestPropertySource - Example

In this section, we will learn about @TestPropertySource annotation. @TestPropertySource is a class level annotation.  It allows us to set test properties for a specific test, taking precedence over default property sources like Java system properties, operating system's environments etc. So the test property files or  inlined properties can be used to override properties defined in system and application property sources. If we don't want to use a file, we can specify  inlined properties . The inlined properties loaded from @TestPropertySource have higher precedence over the properties loaded from resource locations. 1. @TestPropertySource Property file location @SpringBootTest @TestPropertySource ( "/" ) class FilePropertyInjectionUnitTest { //todo } } Above we specified property file location.  2. @TestPropertySource Inline Properties @SpringBootTest @TestPropertySource (properties = { "" }) public class Prope