I'm new to Spring and struggling with its complexity and opaque documentation. My question is How does one write a minimal @Value test?
Consider this test module, in MinimalValueTest.java.
import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.test.context.ActiveProfiles; @Component @ActiveProfiles("test") public class MinimalValueTest { @Value("${test.property}") public static String testProperty; @Test public void test() { if (testProperty == null) { System.out.println("*** FAILED ***"); } else { System.out.println("*** SUCCEEDED ***"); } // Unit tests will go here } } This test references this property defined in the src/test/resources/application.properties file:
test.property=a_test_property Running this outputs *** FAILED ***.
Extra credit: which Spring documentation best explains how to do this?