Java 如何在config.properties文件中指定测试资源文件路径

Java 如何在config.properties文件中指定测试资源文件路径,java,Java,我在src/test/resources中有一个文件(例如:test.txt),我在同一位置有config.properties文件(src/test/resources)。在config.properties文件中,我有一个属性file\u path,我必须通过test.txt文件的路径才能访问该属性。 如何传递该值 我试过了 file_path=${basedir}/src/test/resources/test.txt file_path=/src/test/resources/test.

我在
src/test/resources
中有一个文件
(例如:test.txt)
,我在同一位置有
config.properties
文件
(src/test/resources)
。在
config.properties
文件中,我有一个属性
file\u path
,我必须通过
test.txt
文件的路径才能访问该属性。 如何传递该值

我试过了

file_path=${basedir}/src/test/resources/test.txt
file_path=/src/test/resources/test.txt
file_path=../src/test/resources/test.txt
file_path=test.txt
但是他们都不工作

我变了

file_path=/src/test/resources/test.txt


然后它工作了

您使用的是什么IDE?您使用test.txt的目的是什么?也许你可以使用一个临时文件来满足你在单元测试中的需要:我在使用EclipseIDE,实际上在测试运行期间,我正在创建该文件,在测试之后删除该文件……然后我肯定会查看我上面发送的链接,它显示了单元测试中文件的最佳实践。或者从控制台而不是从Eclipse运行单元测试。
file_path=src\\test\\resources\\test.txt