尝试使用junit测试Spring项目上的服务时出错

时间:2012-09-19 14:44:37

标签: java spring junit spring-webflow

我正在尝试使用junit在Eclipse Web Flow Project中运行我的第一个测试,并使用mvn测试从控制台运行,但是给了我同样的错误。

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [WEB-INF/spring/root-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/spring/root-config.xml] cannot be opened because it does not exist

我检查过,我确实在该位置有这个文件,所以我不知道为什么Eclipse和Maven没有找到它。有人可以帮帮我......下面是我的测试班

package org.uftwf.memberinquiry.text;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.uftwf.memberinquiry.model.MemberInquiryInformation;
import org.uftwf.memberinquiry.model.MemberRequest;
import org.uftwf.memberinquiry.service.MemberInquiryService;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/WEB-INF/spring/root-config.xml")
public class TestApp {

    @Autowired
    private MemberInquiryService service;

    @Test
    public void testgetMemeberRequestInformation() {

        MemberRequest inMemberRequest = new MemberRequest();

        MemberInquiryInformation testInfo = service.getMemeberRequestInformation(inMemberRequest);

        inMemberRequest.setRequestor("cpilling04@aol.com.dev");


        Assert.assertEquals(testInfo.getFirst_Name(), "Christine");
        Assert.assertEquals(testInfo.getLast_Name(), "Pillings");
    }

}

3 个答案:

答案 0 :(得分:0)

@ContextConfiguration(locations = {classpath:spring/root-config.xml})

或创建

TestApp-context.xml

答案 1 :(得分:0)

我更新了最新的spring-test和junit,现在一切都找到了

答案 2 :(得分:0)

@ContextConfiguration(locations = "classpath:WEB-INF/spring/root-config.xml")

以/开头的路径被理解为绝对路径。