在春季使用Junit测试metod

时间:2016-01-26 19:08:53

标签: java spring maven junit

我正在尝试为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我添加了junitspring-test的依赖关系。

任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

它看起来像你的配置文件'不是spring xml配置:" http://xmlns.jcp.org/xml/ns/config"在此上下文中不是有效的名称空间。