我可以在TemporaryFolder
测试中生成junit
,并使用该文件夹作为@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文件夹。但是如何?