简体   繁体   English

@ContextConfiguration是指什么?

[英]What does @ContextConfiguration refer to?

I've just parachuted into a spring project and they don't believe in unit testing. 我刚刚跳伞到春季项目,他们不相信单元测试。

I am trying to set up my own unit testing environment. 我正在尝试建立自己的单元测试环境。

May I know what does the annotation @ContextConfiguration refer to? 我可以知道@ContextConfiguration注释是什么意思吗?

What about for @Repository, I can't seem to initialize it. 对于@Repository来说,我似乎无法初始化它。

What does the file look like and where is it usually resided? 文件是什么样的,它通常位于何处?

It defines class-level metadata that is used to determine how to load and configure an application context for integration tests. 它定义了类级元数据,用于确定如何为集成测试加载和配置应用程序上下文。

Typically my spring unit test class look like this 通常我的弹簧单元测试类看起来像这样

@ContextConfiguration("/personservicetest-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class PersonServiceTest {
  ...
}

And a spring application context will be built based on personservicetest-context.xml file (relative to classpath root) 并且将基于personservicetest-context.xml文件(相对于类路径根)构建spring应用程序上下文

@ContextConfiguration is used to determine how to load and configure an ApplicationContext in integratrion tests, like in this JUnit test: @ContextConfiguration用于确定如何在integratrion测试中加载和配置ApplicationContext ,就像在这个JUnit测试中一样:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/test5.xml")
public class Test5 {
    @Autowired
    ConnectionFactory f1;

    @Test
    public void test() throws Exception {
...

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

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