- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有这个非常简单的类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:/application-context-this-does-not-exist.xml"})
public class HTMLSourceExtractorImplTest {
@Autowired
ApplicationContext context;
@Test
public void test(){
String [] beans = context.getBeanDefinitionNames();
for(String bean : beans){
System.out.println(bean);
}
System.out.println("Testing");
}
}
在类路径中指定的上下文文件不存在。我几乎可以输入我想要的任何名称,并且代码不会中断。我的意思是测试运行得很好,就好像那个文件真的存在一样。
如果我做了一个小改动,从 : classpath* 到 classpath ,然后它发出尖叫声,说这个文件不存在,这是我期望的行为在第一种情况下也是如此。
Spring 版本 3.2.3.RELEASE。
有人可以解释这种奇怪的行为吗?
编辑
建议的日志内容:
20:47:26,923 INFO [GenericApplicationContext] Refreshing org.springframework.context.support.GenericApplicationContext@3df6c65c: startup date [Fri Jun 07 20:47:26 PDT 2013]; root of context hierarchy
我什至尝试从应用程序上下文中输出所有 beans:
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.annotation.ConfigurationClassProcessor.importAwareProcessor
在我看来,如果使用通配符,Spring 将创建一个默认的空应用程序上下文
最佳答案
引用自 JavaDoc 可能会回答您的问题:
/**
* Pseudo URL prefix for all matching resources from the class path: "classpath*:"
* This differs from ResourceLoader's classpath URL prefix in that it
* retrieves all matching resources for a given name (e.g. "/beans.xml"),
* for example in the root of all deployed JAR files.
* @see org.springframework.core.io.ResourceLoader#CLASSPATH_URL_PREFIX
*/
String CLASSPATH_ALL_URL_PREFIX = "classpath*:";
由于在您的类路径中没有匹配名称 application-context-this-does-not-exist.xml
的 XML 文件,您的配置等于 @ContextConfiguration(locations={ })
=> 清空应用上下文。
然而,当您使用 CLASSPATH_URL_PREFIX = "classpath:"
时,这等于说“加载这个不存在的文件” => 错误加载上下文配置.
关于java - RunWith 和 ContextConfiguration 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16985770/
我有一个 gradle 文件 testCompile('junit:junit') testCompile('org.powermock:powermock-core:1.6.5') testComp
我使用 @RunWith(MockitoJUnitRunner.class) 与mockito 进行 junit 测试。但现在我正在使用 spring boot 应用程序并尝试使用 @RunWith(
在通常使用 @Mock 和 @InjectMocks 注释的模拟中,被测类应该使用 @RunWith(MockitoJUnitRunner.class)。 @RunWith(MockitoJUnitR
@RunWith(MockitoJUnitRunner.class) 和 @RunWith(SpringJUnit4ClassRunner.class) 有什么区别?什么时候合适使用它? 最佳答案 M
在使用 Spring Boot 时,我总是将 @SpringBootTest 添加到我的测试类中,并且我的测试按预期工作。我想知道添加 @RunWith(SpringRunner.class) 能带来
目前我的测试类有以下内容: @RunWith(Parameterized.class) @RunWith(PowerMockRunner.class) public class TestApp ext
我的项目是用 JUnit 5 设置的,我想为我的测试使用不同的 Runner,但我什至不能使用 @RunWith 注释,因为它无法编译。在本指南中,https://www.baeldung.com/j
在不研究 JUnit 源代码本身(我的下一步)的情况下,是否有一种简单的方法可以设置每个测试使用的默认 Runner,而不必在每个测试上设置 @RunWith?我们有大量的单元测试,我希望能够全面添加
我正在从仅使用 Intellij 管理我的构建系统转向使用 Intellij/Maven。当我通过@RunWith(KmlParameterizedRunner.class) 使用我自己的运行器运行我
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 7 年前。 此问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-topic在这里
我有一个自定义测试运行程序来运行部分测试,以便我可以将测试分布在不同的 jenkins 节点上。如果运行所有集成测试,则需要一个小时。所以我有 3 台服务器运行 1/3 的测试,总共只需要 20 分钟
我有注释这些注释的类: @ContextConfiguration(locations = { "classpath:pathToXml.xml" }) @RunWith(Spring
我正在尝试让 RunWith(PowerMockRunner.class) 使用我现有的包注释。 版本: powermock 1.4.12 mockito 1.9.0 junit 4.8.2 pack
我有这个非常简单的类: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath*:/
以下 Java 类无法在我的 IDE (Intellij IDEA) 中运行。 IDE 没有给出任何原因,这使得故障排除变得痛苦和困难。 这个类看起来像这样: import cucumber.api.
这个问题在这里已经有了答案: Initialising mock objects - Mockito (8 个答案) 关闭 6 年前。 我正在使用 Junit 4.8.2。当我使用 @RunWith
我有以下测试代码: package soundSystem; import static org.junit.Assert.*; import org.junit.Test; import org.j
我正在使用 spring boot starter test 编写 JUnit 测试用例。我喜欢使用 JunitParamrunner,它有助于为参数化测试传递文件。基本上它逐行读取文件中的数据,并为
我正在处理 BDD 文件并尝试使用 JUnit 进行测试。 我想将 RunCukesTest 类与 @RunWith(Cucumber.class) 一起使用。 我在很多网站上搜索过如何安装要求,但我
这个注解有什么作用? 我想什么时候使用它? 我什么时候不想使用它? @RunWith(SpringJUnit4ClassRunner.class) 当我使用 Google 搜索时,我可以找到更多的用法
我是一名优秀的程序员,十分优秀!