0


泛微E9单元测试配置及使用教程

前言

编写目的:

为了帮助大家在不启动resin服务的前提下,进行一些二开内容的测试和验证,尽可能的利用单元测试等功能实现在IDEA中便可以进行后端代码的一些测试,从而节省掉反复重启resin服务的不必要的时间浪费。

1、前提条件

  • 将gitee中的项目拉取到本地IDEA中。
  • gitee地址:https://gitee.com/llhtrunk/ecology_dycs/tree/master
  • 配置好必要的ecology/classbean,WEB-INF/lib类库。
  • 保证可以正常引用系统中引用的类库和系统类进行开发和正常编译。

2、修改配置文件

2.1、修改数据库连接配置

修改为实际要连接的ecology数据库

image-20220809140556996

2.2、修改log4j

将log4j中的log日志文件路径修改为绝对路径的具体位置

image-20220809140933740

3、添加junit依赖

image-20220809141156987

4、测试类

测试查询数据库操作是否生效。

packagecom.weavernorth;importorg.junit.Before;importorg.junit.Test;importweaver.conn.RecordSet;importweaver.general.BaseBean;importweaver.general.GCONST;importweaver.hrm.User;importjava.net.InetAddress;importjava.net.UnknownHostException;/**
 * @Classname Test
 * @Description TODO
 * @Version 1.0.0
 * @Date 2022/7/21 0021 16:45
 * @Created by llh
 */publicclassTestAction{@Before//1、设置好根路径publicvoidbefore()throwsException{
        GCONST.setServerName("ecology");
        GCONST.setRootPath("D:\\mywork\\Ecology9单元测试\\ecology\\");String hostname ="Unknown";try{InetAddress addr =InetAddress.getLocalHost();
            hostname = addr.getHostName();}catch(UnknownHostException ex){System.out.println("Hostname can not be resolved");}}@Test//2、执行测试publicvoidtest(){BaseBean baseBean =newBaseBean();RecordSet rs =newRecordSet();//执行数据库查询
        rs.executeQuery("select *  from hrmresource ");while(rs.next()){System.out.println("lastname = "+ rs.getString("lastname"));}//读取配置文件String weaver = rs.getPropValue("weaver","ecology.url");//打印日志
        baseBean.writeLog("weaver", weaver);//构建用户User user =newUser(1);//读取用户信息String loginid = user.getLoginid();System.out.println("loginid = "+ loginid);}}

代码运行结果:
image-20220809141833879

5、利用系统的邮件配置发送邮件

邮件群发设置好发送服务

image-20220810092144123

@Testpublicvoidtest2()throwsException{//收件人,邮箱地址,多地址时用英文逗号分隔String sendTo ="[email protected]";//邮件标题String emailTitle ="这是个标题";//邮件内容String emailInfo ="这是邮件内容";//邮件附件idsString emailFileIds ="";EmailWorkRunnable ewr =newEmailWorkRunnable(sendTo, emailTitle, emailInfo);
    ewr.setImagefileids(emailFileIds.toString());//result:true投递成功,false投递失败boolean emailSendResult = ewr.emailCommonRemind();System.out.println("emailSendResult = "+ emailSendResult);}

发送成功的截图

image-20220810092320013

6、发送消息

目前测试可以发送成功,但是在ecology对应用户中未看到对应消息,未找到原因。

@TestpublicvoidtestMessages()throwsException{// 消息来源MessageType messageType =MessageType.newInstance(100);// 接收人id 必填Set<String> userIdList =newHashSet<>();
    userIdList.add("4");// 标题String title ="标题";// 内容String context ="内容";// PC端链接String linkUrl ="https://www.baidu.com";// 移动端链接String linkMobileUrl ="https://m.baidu.com";try{MessageBean messageBean =Util_Message.createMessage(messageType, userIdList, title, context, linkUrl, linkMobileUrl);// 创建人id
        messageBean.setCreater(1);// 需要修改消息为已处理等状态时传入,表示消息最初状态为待处理//message.setBizState("0");//消息来源code +“|”+业务id需要修改消息为已处理等状态时传入//messageBean.setTargetId("121|22");boolean store =Util_Message.store(messageBean);newBaseBean().writeLog("消息提醒结果="+ store);}catch(IOException e){
        e.printStackTrace();}}

本文转载自: https://blog.csdn.net/u010048119/article/details/129579004
版权归原作者 二开菜鸟 所有, 如有侵权,请联系我们删除。

“泛微E9单元测试配置及使用教程”的评论:

还没有评论