【发布时间】:2020-01-04 09:20:43
【问题描述】:
我正在编写一个从文件中读取文件内容的服务,该位置是从环境变量FILE_LOCATION中读取的。
fn my_function(){
let path = match env::var("FILE_LOCATION") {
...
let contents = match fs::read(&path) {
}
我有一个测试文件test_file.json 在:
proj
resources
test
test_file.json
src
main.rs
tests
unit_tests.rs
在测试中我可以设置FILE_LOCATION:
env::set_var("FILE_LOCATION", "path/to/test/file");
问题是path/to/test/file 的值应该是多少?
或者换句话说:
如何在 Rust 测试中访问外部文件?
【问题讨论】:
标签: unit-testing rust