0

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?

asked Feb 16, 2021 at 21:17
2

1 Answer 1

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

answered Feb 17, 2021 at 5:57
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.