论坛首页 入门技术论坛

spring 3 基于注解的junit单元测试

浏览 8638 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-08-24   最后修改:2010-09-02
package com.javaeye.website.service;

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.javaeye.website.mg.service.CommentManager;
 //使用@RunWith(SpringJUnit4ClassRunner.class),才能使测试运行于Spring测试环境
@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration 注解有以下两个常用的属性:
//locations:可以通过该属性手工指定 Spring 配置文件所在的位置,可以指定一个或多个 Spring 配置文件
//inheritLocations:是否要继承父测试类的 Spring 配置文件,默认为 true
@ContextConfiguration(locations={"classpath:/spring/*-resource.xml",
		 "classpath:/spring/*-validator.xml",
        "classpath:/spring/*-datasource.xml",
        "classpath:/spring/*-dao.xml",
        "classpath:/spring/*-service.xml"})
public class CommentManagerTest {

	@Autowired
	CommentManager manager;
	@Test
	public void indexTest()
	{
	   //发表评论调用service业务方法
	   System.out.println(manager.addComment("comment_ID", "javaEyeComment", "61.129.70.27"));
	}
}

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics