一般在开发中,对于后端代码来讲,也需要编写单元测试,但经常看到的是单元测试代码几乎不写,测试依赖于通过前端调用而进行。
如果没有前端界面,这个时候单元测试代码就会很方便:
/**
* <p>Title: ServiceTest.java</p>
* <p>Description: </p>
* @author wangzhj
* @date 2020年5月18日
* @version 1.0
*/
package com.xxx.xxx.test;
import java.util.List;
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.xxx.xxx.model.gather.DeptDetailModel;
import com.xxx.xxx.service.basics.DeptDetailService;
/**
* <p>Title: ServiceTest</p>
* <p>Description: </p>
* @author wangzhj
* @date 2020年5月18日
*/
@RunWith(SpringJUnit4ClassRunner.class)
// @ContextConfiguration(locations={"classpath:spring/spring-dao.xml","classpath:spring/spring-quartz.xml","classpath:spring/spring-service.xml","classpath:spring/spring-web.xml","classpath:spring/spring-dubbo-provider.xml"})
@ContextConfiguration(locations= {"classpath:spring/spring-*.xml"})
public class ServiceTest {
@Autowired
private DeptDetailService deptDetailService;
@Test
public void testDeptDetailServiceExist(){
System.out.println("==============================="+deptDetailService);
DeptDetailModel dm = new DeptDetailModel();
dm.setId("bb6ae844d35445efb9d68b18c611723c");
List<DeptDetailModel> l = deptDetailService.findDepts(dm);
System.out.println(l);
}
}