如何将Maven资源也用作测试资源 [英] How to use maven resources also as test resources

查看:78
本文介绍了如何将Maven资源也用作测试资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven项目,该项目加载一个xslt文件并执行转换以及对结果的其他处理.通常,当用户运行应用程序时,用户会提供要加载的xslt文件路径.但我包括一些捆绑在我的应用程序中的默认xslt文件,用户可以在不加载任何外部xslt文件的情况下使用它们.为此,我将它们添加到src/main/resources/xslt中.我的问题是我想在测试阶段针对那些xslt文件运行测试.我怎样才能做到这一点?我是否应该将src/main/resources/xslt内容复制到target/somewhere并将其加载到测试类代码中?该使用哪个插件?

I have a maven project that loads an xslt file and executes the transformation along with other processing on the result. Normally when the user runs the application, the user provides the xslt file path to be loaded. But I include some default xslt files bundled inside my application that the user can use without loading any external xslt file. I do this by adding them to src/main/resources/xslt. My problem is that I want to run tests against those xslt files in testing phase. How can I achieve this? Should I copy the src/main/resources/xslt contents to target/somewhere and load these in my test classes code? Which plugin is used for that?

推荐答案

我的问题是我想在测试阶段针对那些xslt文件运行测试.我怎样才能做到这一点?

My problem is that I want to run tests against those xslt files in testing phase. How can I achieve this?

无事可做,target/classes在测试的类路径中.更准确地说,测试的类路径为:

There is nothing to do, target/classes is on the class path of tests. More precisely, the class path for tests is:

  • 第一个target/test-classes
  • 然后target/classes
  • 然后dependencies
  • first target/test-classes
  • then target/classes
  • then dependencies

因此,在测试中可以看到src/main/resources中的资源(已复制到target/classes中).

So resources from src/main/resources (which are copied into target/classes) are visible from tests.

这篇关于如何将Maven资源也用作测试资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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