I'm unit testing code that gets its setup from environment variables. The problem I'm seeing is that @Value() is not finding the keys.
@ContextConfiguration
@TestPropertySource(
properties = {
"foo=bar",
"baz=qux"
})
@Testcontainers
class MyUnitTest {
@Value("${foo}")
private static String theFoo;
@BeforeAll
static void setUp() {
// in the logs this displays as null
LOG.info("foo={}", theFoo);
}
}
if you don't set locations property in
@TestPropertySource,@TestPropertySourcefinds properties file based on the class to which the@TestPropertySourcewas addedfor example, if your class is in "com.demo" package, there must be a "com.demo.xxx.properties" file on the classpath
so you need to do add properties files where
MyUnitTestis located or add locations propertyexample