Spring单元测试
发布日期:2021-06-29 11:46:54 浏览次数:4 分类:技术文章

本文共 1582 字,大约阅读时间需要 5 分钟。

简单的自我练习测试直接依赖junit包用@Test注解就可以

@Testpublic void test01(){    System.out.println(11);}

如果是实战项目里的单元测试,建议用以下方法:

1、写一个基础的测试类BaseTest,设定上下文的配置文件信息,指定运行环境

import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import org.springframework.test.context.web.WebAppConfiguration;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = { "classpath*:config/spring-*.xml" })@WebAppConfigurationpublic class BaseTest {}

2、编写测试类进行测试

import com.hnac.hzinfo.flowable.dao.FlowableCustomSettingMapper;import com.hnac.hzinfo.flowable.entity.FlowableCustomSetting;import org.junit.Test;import org.springframework.beans.factory.annotation.Autowired;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;/** * @Description: 测试类 * @Author zhongyj * @Date 2020/3/11 **/public class MyFlowableTest extends BaseTest{    @Autowired    FlowableCustomSettingMapper settingMapper;    @Test    public void testUpdateBatch() throws Exception{        Map
params = new HashMap
(); List
list = new ArrayList<>(); FlowableCustomSetting s1 = new FlowableCustomSetting(); s1.setActivityId("a1"); s1.setSettingValue("val01"); FlowableCustomSetting s2 = new FlowableCustomSetting(); s2.setActivityId("a2"); s2.setSettingValue("val02"); list.add(s1); list.add(s2); int i = settingMapper.updateBatch(list); System.out.println("updateBatch结果:"+i); }}

 

转载地址:https://blog.csdn.net/zzchances/article/details/104798595 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Spring实现日志切面
下一篇:flowable自定义节点属性

发表评论

最新留言

很好
[***.229.124.182]2024年04月16日 20时19分02秒