JUnit单元测试中获取Spring中的bean测试类的编写
2019-02-15 14:37
274 查看
1、编写测试类
[code]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 com.hp.approval.single.impl.SingleInterfaceManager; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath*:/spring/context-*.xml"})//从web.xml中获取contextConfigLocation路径 public class TestInterface { @Autowired private SingleInterfaceManager manager; @Test public void TestApproval(){ manager.checkSingleApproval(); } }
2.web.xml格式
相关文章推荐
- 用junit测试获取spring bean 报No Scope registered for scope 'session'错
- junit测试spring整合ActiveMQ编写消费者代码报错:org.springframework.beans.factory.BeanCreationException: Error crea
- Spring依赖注入,在main方法或junit测试类里获取得Spring容器
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringBoot中Junit测试注入Bean失败的解决方法
- Junit单元测试中获得spring bean
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- spring && Cobertura && maven &&junit 单元测试以及测试覆盖率
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- Spring 集成测试1(对spring管理的bean进行单元测试,借助于spring提供的test case简化测试)
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringBoot Junit 测试加载 xml 读取 bean 失败
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- Junit测试一个spring静态工厂实例化bean的例子,出现java.lang.IllegalArgumentException异常。
- spring结合junit进行单元测试(二)——测试后进行事务回滚
- 【转】SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法