[英]What is the recommended way to share resources between source code and tests in java?
I have some files in the src/main/resources
folder which are used by the application I'm working on and I copied over several of them to the src/test/resources
folder so that my tests can access them easily. 我在
src/main/resources
文件夹中有一些文件,这些文件供我正在使用的应用程序使用,我将其中几个文件复制到src/test/resources
文件夹中,以便我的测试可以轻松访问它们。 I was wondering whether this is the best practice when it comes to unit testing or not? 我想知道这是否是单元测试的最佳实践? For example I could load the resources from
src/main/resources
and in that way my tests would fail if someone changed the source code. 例如,我可以从
src/main/resources
加载资源,这样,如果有人更改了源代码,我的测试将失败。 What is the best practice for this? 最佳做法是什么?
The files in src/main/resources
are available during testing, I've just comfirmed this is the case for me. src/main/resources
中的文件在测试过程中可用,我只是确认了这种情况。 You can override these resources by adding them to src/test/resources
but as far as I'm aware you can't hide them from the tests so it would look as though there is a configuration error on your system. 您可以通过将它们添加到
src/test/resources
来覆盖这些资源,但据我所知您无法将它们隐藏在测试中,因此看起来好像系统上存在配置错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.