简体   繁体   English

在Java中的源代码和测试之间共享资源的推荐方法是什么?

[英]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.

相关问题 在一组程序员之间共享Java源代码新版本的最佳方法是什么? - What is the best way to share the new version of Java source code between a group of programmers? 在java中访问网络共享文件夹(位于Windows或Linux中)的推荐方法是什么? - What is the recommended way of accessing a network share folder (located in Windows or Linux) in java 在具有不同基类的活动之间共享代码的最佳方式是什么? - What is the optimal way to share code between Activities with different base classes? 在Java中,枚举值之间共享功能的最佳方法是什么? - In Java, what is the best way to share functionality between enum value? 在Java程序中的两个HTTPClient之间共享会话的好方法是什么? - What is a good way to share a session between two HTTPClients in a Java program? 在Java中使用计时器的最推荐方法是什么 - What is the most recommended way to using timer in Java 在JAVA中建议增加日期的方法是什么? - What is the recommended way to increment date in JAVA? 在应用程序之间共享Java代码的最佳方法是什么 - What is the best way to share Java code across applications 这个java源代码在java中创建对象有什么区别? - What different between this java source code to create object in java? 在Java应用程序中使用C源代码的最简单方法是什么? - What's the easiest way to use C source code in a Java application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM