繁体   English   中英

如何找到Surefire / Junit4测试将搜索的类路径?

[英]How can I find the classpath that a Surefire/Junit4 test will search?

我需要覆盖作为基于Maven的构建的一部分运行的JUnit测试中的一些属性。 为了做到这一点,我需要弄清楚在我们的测试环境中将覆盖文件放在何处。 如何确定此行在测试环境中运行时检查的类路径?

stream = getClass().getClassLoader().getResourceAsStream(resourceName);

我已经检查了ClassLoader的javadoc,但在这一点上它并不是非常清楚。

要查找类路径,您只需使用maven的dependency:build-classpath插件:

mvn dependency:build-classpath -DincludeScope=test

这将为您提供运行surefire时使用的完整类路径。 实际上,includeScope = test是默认值,所以你可以错过它。 否则,您可以指定任何范围,例如compile:

mvn dependency:build-classpath -DincludeScope=compile

调试输出怎么样?

mvn --debug clean install

这将输出你需要的几乎所有东西。 按照加载的顺序包含类路径。

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Determined Maven Process ID 15288
[DEBUG] boot classpath:  
\<REPO>\org\apache\maven\surefire\surefire-booter\2.21.0\surefire-booter-2.21.0.jar  
\<REPO>\org\apache\maven\surefire\surefire-api\2.21.0\surefire-api-2.21.0.jar  
\<REPO>\org\apache\maven\surefire\surefire-logger-api\2.21.0\surefire-logger-api-2.21.0.jar  
\<PROJECT>\src\target\test-classes  
\<PROJECT>\src\target\classes  
\<REPO>\<all your dependencies> 
\<classpath configured as additionalClasspathElement>  
\<REPO>\org\apache\maven\surefire\surefire-junit4\2.21.0\surefire-junit4-2.21.0.jar

boot(compact) classpath:  
<exact same thing as above without full file paths>

Forking command line: 
cmd.exe /X /C ""C:\Program Files\Java\jdk1.8.0_121\jre\bin\java" -ea -jar C:\<TEMP>\surefire3859643060701954342\surefirebooter6402473409535798561.jar C:\<TEMP>\surefire3859643060701954342 2018-06-04T11-50-05_916-jvmRun1 surefire7765693984737889544tmp surefire_08839138260978763550tmp"

Running <all my test cases>

暂无
暂无

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

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