Java 尝试使用junit在Spring项目上测试服务时出错
我试图在一个SpringWebFlow项目上运行我的第一个junit测试,它来自Eclipse内部,也来自带有mvn测试的控制台,但给出了相同的错误Java 尝试使用junit在Spring项目上测试服务时出错,java,spring,junit,spring-webflow,Java,Spring,Junit,Spring Webflow,我试图在一个SpringWebFlow项目上运行我的第一个junit测试,它来自Eclipse内部,也来自带有mvn测试的控制台,但给出了相同的错误 org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [WEB-INF/spring/root-config.xml]; nested exception is
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");
}
}
或创造
TestApp-context.xml
我更新了最新的spring测试和junit,现在一切都找到了
@ContextConfiguration(locations = "classpath:WEB-INF/spring/root-config.xml")
当您以/开始路径时,它被理解为绝对路径。在允许TestExecutionListener[org.springframework.test.context.support]时捕获异常。DependencyInjectionTestExecutionListener@39e4853f]准备测试实例[org.uftwf.memberinquiry.text]。TestApp@49e808ca]org.springframework.beans.factory.BeanDefinitionStoreException:IOException解析类路径资源[WEB-INF/spring/root config.XML]中的XML文档;嵌套的异常是java.io.FileNotFoundException:无法打开类路径资源[WEB-INF/spring/root config.xml],因为它不存在。只需复制我的变量而不使用[WEB-INF/spring/还有一个问题,根配置是应用程序的applucation配置吗?如果是,请在test/resources文件夹中创建测试配置,并导入应用程序configyes,但它是WEB项目的配置。测试资源中的配置如何加载WEB-INF中的配置?我将它们移动到了test/resource,它看起来更好。我是现在Getting java.lang.NoClassDefFoundError:org/junit/Assumption$AssumptionViolatedException该错误非常简单,为什么要尝试从特定的类路径文件夹加载测试上下文?只需将其设置为相对于您的测试类即可
@ContextConfiguration(locations = "classpath:WEB-INF/spring/root-config.xml")