【发布时间】:2020-03-01 22:46:39
【问题描述】:
我可以在junit 测试中生成TemporaryFolder,并将该文件夹用作@Value 属性的前缀吗?
@RunWith(SpringRunner.class)
@SpringBootTest
public class MyTest {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
@Autowired
private MyService service;
@Test
public void test() {
//TODO how to rewrite the application property with the tmp folder created?
service.run();
}
}
@Service
public class MyService {
@Value("${my.export.path}")
private String path;
public void run() {
//generates a file and exports it to @Value path
}
}
application.properties:
my.export.path=/var/www/export.csv
我当然想将导出路径设置为生成的 tmp 文件夹。但是怎么做呢?
【问题讨论】:
标签: java spring spring-boot junit spring-boot-test