在eclipse中运行单元测试春季时,将src / main / resources添加到classpath [英] Add src/main/resources to classpath when running unit test in eclipse for spring

查看:525
本文介绍了在eclipse中运行单元测试春季时,将src / main / resources添加到classpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在eclipse中,我的maven项目有一个'src / main / resources /'文件夹和一个'src / test / resources'文件夹。两个目录的内容似乎进入项目/目标/类,只有src / test / resources目录的内容进入项目/目标/测试类。

In eclipse my maven project has a 'src/main/resources/' folder and a 'src/test/resources' folder. The contents of both directories seem to go into 'Project/target/classes', and the content of just the 'src/test/resources' directory goes into 'Project/target/test-classes'.

当我使用spring在测试时加载类路径资源时,似乎只有可用的classpath中的'test-classes'文件夹中的东西。这是有道理的,因为只有测试资源进入测试类路径。

When I use spring to load a classpath resource whilst testing, it seems to only have available the stuff that's in 'test-classes' folder on the classpath. This makes sense, as only testing resources go in the classpath for testing.

然而,我希望我的主要资源在运行单元测试时可用,但是无法找到当运行单元测试时,它们不在类路径上。如何配置我的方法来解决这个问题?

However I want my main resources to be available when running unit tests aswell, but they cannot be found when running unit tests as they are not on the classpath. How do I configure my way around this problem?

推荐答案

您可以配置surefire插件(这是maven用于运行单元测试)包括任何其他类,jar或资源目录。

You can configure the surefire plugin (which is what maven uses to run unit tests) to include any additional classes, jars or resource directories.

http://maven.apache.org/plugins/maven-surefire-plugin/examples/configuring-classpath.html

这篇关于在eclipse中运行单元测试春季时,将src / main / resources添加到classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆