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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值