在Java8到Java11的迁移中,单元测试失败了

在Java8到Java11的迁移中,单元测试失败了,java,eclipse,maven,junit,classpath,Java,Eclipse,Maven,Junit,Classpath,我正在将我的项目从Java8迁移到Java11。所以我使用了Spring5.1.0、Java11、Eclipse4.16和Tomcat9。我能够成功地构建源代码。但是当涉及到测试时,他们就失败了 下面是我在pom.xml中为测试准备的内容 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12<

我正在将我的项目从Java8迁移到Java11。所以我使用了Spring5.1.0、Java11、Eclipse4.16和Tomcat9。我能够成功地构建源代码。但是当涉及到测试时,他们就失败了

下面是我在pom.xml中为测试准备的内容

<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.12</version>
   <scope>test</scope>
   <type>jar</type>
</dependency>
<dependency>
   <groupId>org.mockito</groupId>
   <artifactId>mockito-core</artifactId>
   <version>2.27.0</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-module-junit4</artifactId>
   <version>2.0.2</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-api-mockito2</artifactId>
   <version>2.0.2</version>
   <scope>test</scope>
</dependency> 
我已经给出了测试类结构的示例

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
public class SomeTestClass {
   ...
}
由于提到的异常,它将失败。但是,我做了一些研究,发现了一个解决办法,即 更改为:

@ContextConfiguration(locations = {"classpath:test-context.xml"})
为此:

@ContextConfiguration(locations = {"classpath*:/spring/test-context.xml"})

它是有效的。但问题是我不允许编辑源代码。如何实现它?

如果包含“spring”目录的目录是类路径中的目录,而不是“spring”目录本身,那么这不是一个“解决方法”,而是一个“修复”。如果不允许更改任何内容,则也无法修复任何内容。

根据您的修复,似乎
测试上下文.xml
现在位于
类路径*:/spring/test context.xml
。因此,您可以尝试将
testcontext.xml
所在的spring文件夹添加到类路径中,然后它就可以工作了。此解决方案不需要更改代码。您可以在

上阅读如何操作“不允许编辑源代码”是什么意思?你和程序员谈过了吗?你和你的老板谈过了吗?确切地说,不允许更改源代码是什么意思?你正在研究迁移,对吗?然后,在这种情况下,您必须修改源代码。尽可能通过github提供代码库。
@ContextConfiguration(locations = {"classpath*:/spring/test-context.xml"})