2

我刚刚跳伞到一个春季项目,他们不相信单元测试。

我正在尝试建立自己的单元测试环境。

我可以知道注释@ContextConfiguration指的是什么吗?

@Repository 怎么样,我似乎无法初始化它。

该文件是什么样的,它通常位于何处?

4

2 回答 2

2

它定义了类级元数据,用于确定如何为集成测试加载和配置应用程序上下文。

通常我的弹簧单元测试类看起来像这样

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

并且将基于 personservicetest-context.xml 文件(相对于类路径根)构建一个 spring 应用程序上下文

于 2013-08-01T07:03:17.257 回答
2

@ContextConfiguration用于确定如何加载和配置ApplicationContext集成测试,例如在此 JUnit 测试中:

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

    @Test
    public void test() throws Exception {
...
于 2013-08-01T07:06:14.893 回答