Unit Test With Spring Annotation
2012-12-14 10:13
363 查看
Unit Test
DAO
Dao Impl
Spring Context
package com.example.app.service; import static org.junit.Assert.*; import org.junit.Before; 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.*; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"/springcontext.xml"}) public class TestLeagueService { @Autowired LeagueService service; @Test public void test() { assertNotNull(service.getLeagueDAO()); } }
DAO
package com.example.app.dao.impl.hibernate; public interface LeagueDAO { }
Dao Impl
package com.example.app.dao.impl.hibernate; public class LeagueHibernateDAO implements LeagueDAO { public LeagueHibernateDAO() { super(); } }
Spring Context
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config/> <context:component-scan base-package="com.example"/> <bean id="LeagueDAO" class="com.example.app.dao.impl.hibernate.LeagueHibernateDAO" /> <bean id="LeagueService" class="com.example.app.service.LeagueService" /> </beans>
相关文章推荐
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-003编写JPA-based repository( @PersistenceUnit、 @PersistenceContext、PersistenceAnnotationBeanPostProcessor)
- [Python + Unit Testing] Write Your First Python Unit Test with pytest
- spring扫描出现Annotation-specified bean name 'userService' for bean class [com.test.service.UserService]
- Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test java.lang.IllegalStateException
- Create a simple unit test project with Visual Studio Unit Testing Framework
- unit test with fixture
- Spring Cache Unit Test
- spring unit test start error
- Getting start with OCMock in you unit test
- Spring下的业务层Unit Test修正版
- Spring下的Unit Test Notes 2nd
- JUnit integration test with Spring
- Spring Boot UnitTest
- How to write unit test for CommonsMultipartFile with Mock
- Struts2+Spring的UnitTest编写(使用StrutsTestCase的子类StrutsSpringTestCase)
- unit test use EasyMock:Possible matches are marked with (+1):
- dbunit-spring-test和maven-dbunit-plugin使用
- @FeignClient with top level @RequestMapping annotation is also registered as Spring MVC handler
- Configure a Spring JMS application with Spring Boot and annotation support
- Spring Boot的单元测试(Unit Test)