您的位置:首页 > 编程语言 > Java开发

Unit Test With Spring Annotation

2012-12-14 10:13 363 查看
Unit Test
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: