您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > junit
Spring框架和Junit框架結(jié)合使用案例
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2016/1/28 11:28:55 ] 推薦標(biāo)簽:軟件測(cè)試 單元測(cè)試工具
1 package ltssh;
2
3 import org.junit.Test;
4 import org.junit.runner.RunWith;
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.test.context.ContextConfiguration;
7 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
8
9 import com.lt.bean.Content;
10 import com.lt.dao.content.IContentDao;
11
12 /**
13  *
14  * 類(lèi): JunitSpringTest <br>
15  * 描述: spring框架和junit框架結(jié)合使用案例 <br>
16  * 使用注解的方式讀取配置文件,自動(dòng)注入dao進(jìn)行測(cè)試
17  * 有點(diǎn):干凈整潔,代碼優(yōu)雅
18  * 注意:@RunWith  @ContextConfiguration這兩個(gè)注解的使用
19  *         我是導(dǎo)入了新版本的junit.jar和hamcrest-core-1.3.jar
20  *         junit-4.4.jar版本的不支持
21  */
22 @RunWith(SpringJUnit4ClassRunner.class)
23 @ContextConfiguration(locations={"classpath:applicationContext.xml"})
24 public class JunitSpringTest {
25
26     @Autowired
27     private IContentDao contentDao;
28
29     @Test
30     public void handler(){
31         Content content = contentDao.get(1);
32         System.out.println(content.getTitle());
33     }
34 }
package ltssh;
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.lt.bean.Content;
import com.lt.dao.content.IContentDao;
/**
*
* 類(lèi): JunitSpringTest <br>
* 描述: spring框架和junit框架結(jié)合使用案例 <br>
* 使用注解的方式讀取配置文件,自動(dòng)注入dao進(jìn)行測(cè)試
* 有點(diǎn):干凈整潔,代碼優(yōu)雅
* 注意:@RunWith  @ContextConfiguration這兩個(gè)注解的使用
*         我是導(dǎo)入了新版本的junit.jar和hamcrest-core-1.3.jar
*         junit-4.4.jar版本的不支持
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class JunitSpringTest {
@Autowired
private IContentDao contentDao;
@Test
public void handler(){
Content content = contentDao.get(1);
System.out.println(content.getTitle());
}
}
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd