`

Junit在spring中使用

阅读更多

我们在做web项目的时候,可能有的人负责前台开发(页面+控制层Controller),有的负责service层开发、有的负责dao层开发,不知道你们是不是等所有开发完成后,再联调还是,如果你使用junit,就可以提前测试自己的开发的代码是否OK,下面我说下junit的简单使用:

 

1,一般我们会创建一个test目录,底下放置的代码结构跟我们src下面的代码结构保持一致

 

2,创建测试类,如下:

 

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.huawei.galaxy.mybatis.dao.IMessageQueneMapper;

@ContextConfiguration(locations = {"file:WebRoot/WEB-INF/config/spring-common.xml"}) //加载spring容器

@RunWith(SpringJUnit4ClassRunner.class)//使用spring的测试类

public class ServiceTest {

// 注入bean

@Resource  

IMessageQueneMapper msgMapper;

 

@Test

public void testMsg() {

Map<String, String> paramMap = new HashMap<String, String>();

paramMap.put("msgId", "123");

paramMap.put("msgBody", "test");

msgMapper.msg(paramMap);

}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics