package com.chen.test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.chen.dao.appDao.demoDao;
import com.chen.model.appModel.demoModel;
import com.chen.service.userSystem.appI.demoService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:/spring/applicationContext.xml"})
public class Ttest {
@Autowired
private demoDao dao;
@Autowired
private demoService service;
/**
* 调用dao层方法
*/
@Test
public void test01() {
demoModel model = new demoModel();
model.setOpenId("ogwH2UjwguI13QRC73TYA");
model.setXz("武昌区");
model.setYmurl("www.baidu.com");
model.setScsj("2018-11-23 08:18:12");
dao.adddemo(model);
System.out.println("运行");
}
/**
* 调用业务层方法
*/
@Test
public void test02() {
demoModel model = new demoModel();
model.setOpenId("ogH2Ujg3QRC73TYA");
model.setXz("武昌区");
model.setYmurl("www.baidu.com");
Map<String, Object> adddemo = service.adddemo(model);
System.out.println("运行"+adddemo);
}
}
步骤:
1.项目–>右键–>build Path
–>Configure Build Path...
–>Libraries
–>Add Library
–>JUnit
–>Next
版本version 选JUinut4
(和JUinut5
比较相对稳定)
Finish
2.测试类上添加导入下面两列代码
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:/spring/applicationContext.xml"})
3.测试类上加注解@Test
4.方法调用与控制层,业务实现层类调用方法一致,引用接口,调用方法。
5.测试类完整使用案例可查看顶部引用的代码。