Here is the class that gets its pathToFile from application.properties.
@Component
public class CSVReader {
@Value("${name.basics}")
private String pathToFile;
(other code)
}
The problem is: how can I substitute application.properties for testing?
-
baeldung.com/spring-tests-override-propertiesLesiak– Lesiak2021年02月16日 21:20:34 +00:00Commented Feb 16, 2021 at 21:20
-
1Does this answer your question? How do I mock an autowired @Value field in Spring with Mockito?Januson– Januson2021年02月16日 21:22:06 +00:00Commented Feb 16, 2021 at 21:22
1 Answer 1
You can use spring boot test annotation:
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"name.basics=whatever"})
public class YourTestClass {
@Autowired
CSVReader cvsReader;
@Test
public void yourTest() {
//...
Second option is to put application-test.properties containing replacements in src/test/resources folder of your project
Sign up to request clarification or add additional context in comments.
Comments
lang-java