当我尝试对Spring Hibernate DAO类进行单元测试时出现以下错误。只有当我尝试在tomcat上部署应用程序时才会出现此错误,而不是在执行单元测试时。当我注释掉测试类并测试依赖项时,不会出现错误。
...Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.Resource...
我对Maven的Spring DAO测试依赖如下:(我使用的是Spring版本4.0.5.RELEASE)
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
<optional>true</optional>
</dependency>
我的单元测试课程如下:
@TransactionConfiguration(defaultRollback = true)
@ContextConfiguration({ "classpath:spring/*.xml" })
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
public class EmployerDaoHbnTest {
@Inject
EmployerDao employerDao;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testRegisterEmployer() {
assertTrue(employerDao.findEmployer(5) != null);
}
@Test
public void testToString() {
fail("Not yet implemented");
}
}
我缺少什么依赖?我在哪里可以正式(例如Spring文档)找到Spring DAO测试的依赖项究竟是什么?
答案 0 :(得分:0)
尝试使用此注释进行更改
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:/applicationContext.xml"})
@WebAppConfiguration
我相信你们的一部分问题是交易性的