I'm trying to pick up some config from application.properties and then override it in the unit test. However, the unit test always sets the schemaPath property to null
.
This is what I have:
Service
:
@Service
public class XmlValidator {
@Value("${schema.location}")
private String schemaPath;
public void validateXml(String fileName) {
String schemaPath = null;
if (fileName.contains("Reference")) {
schemaPath = schemaPath;
}
}
}
application.properties and application-test.properties:
schema.location = /schema/Schema_Reference_0.1.xsd
Unit test:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = XmlValidator.class)
@TestPropertySource(locations="classpath:config/application-test.properties")
public class XmlValidatorTest {
private XmlValidator validator = new XmlValidator();
@Test
public void testSchema() throws Exception {
validator.validateXml("resources/xmlFile.xml");
}
}