作者:Java兔
參考資料:http://blog.csdn.net/u013041642/article/details/71430293
測試環境:
SpringMvc + Spring + Mybatis+ Maven
測試版本:
Junit : 4.12
Spring + SpringMvc : 4.2.3.RELEASE
測試文件:
package hjp;
import org.junit.Ignore;
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.alibaba.fastjson.JSONObject;
import com.wx.app.ygp.service.comm.AutoGenerateCustCodeService;
/**
* 針對AutoGenerateCustCodeService接口的單元測試
* @author huangjp
* 2017年7月24日 下午6:10:38
* 遇到問題:
* Error creating bean with name 'loginController'(途中一直以爲是攔截器的問題,雖然問題解決了,但仍然不明白其中的原理)
* 原因:
* @ContextConfiguration中加入了"classpath:spring-mvc.xml"配置導致
* 解決方案 :
* 1、刪除"classpath:spring-mvc.xml"配置
* 2、spring-mvc.xml文件中刪除針對action包的掃描配置(<context:component-scan base-package = "com.wx.app.ygp.action"....>)
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-core.xml","classpath:spring-mybatis.xml",
"classpath:spring-ht.xml","classpath:spring-task.xml"})
public class AutoGenerateCustCodeTest{
@Autowired
private AutoGenerateCustCodeService autoGenerateCustCodeService;
@Test
public void test() throws Exception {
//區域編碼
String regionCode = "3604250013";
//部門編碼
String deptCode = "000101";
//需要自動生成的戶號的個數
int length = 2;
JSONObject result = autoGenerateCustCodeService.generateCustCode(regionCode, deptCode, length);
System.out.println(result.toJSONString());
}
}
具體的配置文件的配置可以參考參考資料。