【发布时间】:2016-01-26 19:08:52
【问题描述】:
我正在尝试为spring 项目编写一些单元测试。这是我要测试的类和测试:
@Component
public class EmployeeManager implements QuestionDAO {
private Manager manager;
@Autowired
public EmployeeManager(Manager manager) {
this.manager = manager;
}
public Category getSpecificCategory(Employee employee) {
return employee.getCategory();
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/config.xml" })
public class EmployeeManagerTest extends MockObjectTestCase {
private EmployeeManager employeeManager;
@Autowired
private Manager manager;
@Override
public void setUp() {
this.manager = mock(Manager.class);
this.employeeManager = new EmployeeManager(manager);
}
@Test
public void testGetSpecificCategory() {
this.employeeManager.getSpecificCategory(new Employee("john","developer"));
}
}
运行上面的测试时,我得到了
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://xmlns.jcp.org/xml/ns/config]
Offending resource: class path resource [META-INF/config.xml]
在pom.xml 中,我添加了junit 和spring-test 的依赖项。
【问题讨论】: