简体   繁体   English

如何增加SpringJUnit4ClassRunner使用的类路径?

[英]How to augment the classpath used by SpringJUnit4ClassRunner?

To be clear, my problem is not that my tests cannot find the application context. 需要明确的是,我的问题不是我的测试无法找到应用程序上下文。 My problem is that other files that are searched for on the classpath cannot be found. 我的问题是找不到在类路径上搜索的其他文件。 My pom.xml runs the tests with additional classpath entries, so the build works fine, but it's annoying that if I want to run the tests manually in Eclipse, I have to edit the run configuration to add a particular subdirectory of the project to the classpath. 我的pom.xml使用附加的类路径条目运行测试,因此构建工作正常,但令人讨厌的是,如果我想在Eclipse中手动运行测试,则必须编辑运行配置,以将项目的特定子目录添加到类路径。 I'd really like to figure out how to specify this in the test class itself. 我真的很想弄清楚如何在测试类本身中指定它。 The "@ContextConfiguration" annotation comes close to this, but that's just for loading the application context. “ @ContextConfiguration”注释与此接近,但这仅用于加载应用程序上下文。

How can I specify in an annotation in the test class itself that a particular subdirectory of the project needs to be added to the classpath when the test runs? 如何在测试类本身的注释中指定在测试运行时需要将项目的特定子目录添加到类路径中?

How can I specify in an annotation in the test class itself that a particular subdirectory of the project needs to be added to the classpath when the test runs? 如何在测试类本身的注释中指定在测试运行时需要将项目的特定子目录添加到类路径中?

That's unfortunately not possible. 不幸的是,这是不可能的。

You'll need to ensure that you can properly import your Maven project into Eclipse -- for example, with the M2Eclipse plugin . 您需要确保可以将Maven项目正确导入到Eclipse中(例如,使用M2Eclipse插件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM