我需要覆盖作为基于Maven的构建的一部分运行的JUnit测试中的一些属性。为了做到这一点,我需要弄清楚在我们的测试环境中将覆盖文件放在何处。如何确定此行在测试环境中运行时检查的类路径?
stream = getClass().getClassLoader().getResourceAsStream(resourceName);
我已经检查了ClassLoader的javadoc,但在这一点上并不是非常清楚。
答案 0 :(得分:3)
要查找类路径,您只需使用maven的dependency:build-classpath插件:
mvn dependency:build-classpath -DincludeScope=test
这将为您提供运行surefire时使用的完整类路径。实际上,includeScope = test是默认值,所以你可以错过它。否则,您可以指定任何范围,例如compile:
mvn dependency:build-classpath -DincludeScope=compile
答案 1 :(得分:0)
如何调试输出?
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>