【问题标题】:Test methods using Junit in spring春季使用Junit的测试方法
【发布时间】: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 中,我添加了junitspring-test 的依赖项。

【问题讨论】:

    标签: java spring maven junit


    【解决方案1】:

    看起来您的“config.xml”不是 spring xml 配置:“http://xmlns.jcp.org/xml/ns/config”在此上下文中不是有效的命名空间。

    【讨论】:

      猜你喜欢
      • 2011-09-26
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      相关资源
      最近更新 更多