软件测试经理工作日常随记【5】-测试人员如何利用好Jenkins集成

集成

Jenkins,一个开源的持续集成(Continuous Integration)工具,它可以帮助开发团队自动化构建、测试和部署应用程序。

Jenkins构建-关于接口自动化及测试管理

Jenkins的作用不用我多说大家都知道,部署环境、定时跑任务。那在测试工作的环节上就免不了跟测试自动化挂钩上。

下面我将从两方面介绍Jenkins在刷新和完善我的测试知识体系中的举足轻重的作用。

1、接口自动化

之前我介绍到jmeter自动化脚本的编写。
写完呢,每次测试的时候都大费周章的打开jmeter,然后一线程一线程的执行,然后再去根据结果树,一个一个的查看结果、分析。如果领导需要一份测试报告,还要费尽脑汁的重立框架、组织语言去总结输出文档。NoNoNo 这绝不是一个成熟的测试工程师的工作样本。以始为终,为降本增效,我们就需要利用到Jenkins了。

  • 创建源码仓库
    首先,把我们编写的脚本上传到代码仓库。日常工作中我们用到的是GitLab
    gitlab新建项目
    新建项目复制仓库地址
  • 利用pycharm push代码
    commit代码

push代码

  • 源码管理
    源码管理

  • 构建触发器
    构建触发器

  • 构建
    构建

  • 构建后操作
    构建后操作-邮箱通知

接口自动化构建后操作-测试数据分析结果告知项目组

邮件通知

测试报告

2、自动化管理禅道

某天老板叫我到办公室,严肃地问了我一个问题:你觉得目前的开发人中,谁的水平最高,工作效率最快。好家伙,这不能妥妥得罪人的问题么,这开发老师我们平时可是放在手心上哄的呀。这锅我不能背,那就让数据说话吧。于是乎,我想到禅道,禅道可是妥妥记录开发在测试员的整个‘成长历史’:模块开发时长、开发产生bug数、bug修复时长、bug激活次数、bug的遗留个数等等。我反手就打开我的pycharm,整了以下关于禅道的sql语句,统计出我要的数据,通过python的整理,以htlml的格式将数据每日定时发送至钉钉群,方便老板以及各部门领导更好的每日观察各位开发的工作情况。

具体统计sql语句代码如下
def bug_total(self, cursor, now,begin_day,total_day):
    """
    最近总的BUG情况统计统计
    :param: day 根据输入天数
    :return:
    """
  
    # 新增bug数
    new_near_bug_sql = """SELECT COUNT(*) as new_near_bug from zt_bug where openedDate between "%s" and "%s" and deleted='0';""" % (begin_day, now)
    cursor.execute(new_near_bug_sql)
    new_near_bug = cursor.fetchone()
    # print("新增bug数")
    # print(new_near_bug)

    # 已解决bug数
    close_bug_sql = """SELECT COUNT(*) as close_bug from zt_bug where status = "closed" and openedDate between "%s" and "%s" and deleted='0';""" % (begin_day, now)#"%s"表示这里将被替换成一个新的字符串,依次为recent_sevenday, now
    cursor.execute(close_bug_sql)
    close_bug = cursor.fetchone()
    # print("已解决bug数")
    # print(close_bug)

    # 未解决bug数
    open_bug_sql = """SELECT COUNT(*) as open_bug from zt_bug where status = "active" and openedDate between "%s" and "%s" and deleted='0';""" % (begin_day, now)
    cursor.execute(open_bug_sql)
    open_bug = cursor.fetchone()
    # print("没解决bug数",)
    # print(open_bug)

    # 已解决待验证bug数
    close_unbug_sql = """SELECT COUNT(*) as close_unbug from zt_bug where status = "resolved" and openedDate between "%s" and "%s" and deleted='0';""" % (begin_day, now)
    cursor.execute(close_unbug_sql)
    close_unbug = cursor.fetchone()
    # print("已解决待验证bug数", )
    # print(close_unbug)

    #研发人员发生bug数排行。
    dev_bug_sql = """SELECT COUNT(*) num,realname FROM zt_bug b INNER JOIN zt_user u ON u.account = b.resolvedBy
                        WHERE DATE_FORMAT(b.openedDate, '%%Y-%%m-%%d') between '%s' and '%s'
                        AND u.deleted='0' AND u.role='dev' 
                        GROUP BY b.resolvedBy ORDER BY num DESC;""" % (total_day, now)
    cursor.execute(dev_bug_sql)
    dev_bug = cursor.fetchall()
    print("研发人员发生bug数降序排行", )
    # print(dev_bug)
    add_str_dev_bug = ''  # 空字符串
    #让降序排行一行一人
    for _tuple in dev_bug:
        a = ' \n \n {0}'.format(
            _tuple)
        add_str_dev_bug += str(a)
        
        
 #研发人员发生bug激活数排行。
    activation_bug_sql = """SELECT SUM(激活次数) 激活次数,中文姓名 FROM (SELECT b.id,COUNT(*) 激活次数,u.realname 中文姓名 FROM
        zt_bug b INNER JOIN zt_action a ON a.objectID = b.id INNER JOIN zt_user u ON u.account = b.resolvedBy
        WHERE DATE_FORMAT(b.openedDate, '%%Y-%%m-%%d') between "%s" and "%s" AND a.objectType = 'bug' AND a.action = 'activated'
        AND u.deleted='0'  and u.role='dev'
        GROUP BY b.id ORDER BY 激活次数 DESC) tem GROUP BY tem.中文姓名 ORDER BY 激活次数 DESC;""" % (total_day, now)
    cursor.execute(activation_bug_sql)
    activation_bug = cursor.fetchall()
    print("研发人员BUG被激活次数(非一次性修复)", )
    print(activation_bug)
    add_str_activation_bug = ''  # 空字符串
    #让降序排行一行一人
    for _tuple in activation_bug:
        a = ' \n \n {0}'.format(
            _tuple)
        #(Decimal('19')中的(Decimal('')去掉
        a = re.sub('[(Decimal('')]', '', a)
        # print(a)
        add_str_activation_bug += str(a)

    # print("拆开元组,研发人员BUG被激活次数(非一次性修复)", )
    # print(add_str_activation_bug)


    # 提BUG、指派、转派【已解决待验证】、改BUG,=====================\n\n研发人员BUG被激活次数(非一次性修复):{5}\n\n
    statistics_bug = "本年度新增bug总情况({6}~{7}) \n\n 新增BUG数:{0} \n\n 未关闭BUG数:{1} \n\n 已关闭BUG数:{2} \n\n 已解决待验证BUG数:{3}\n\n =====================\n\n研发人员今年(2023)BUG数倒序:\n\n{4}\n\n =====================\n\n研发人员今年BUG被激活次数(非一次性修复):\n\n{5}\n\n".format(
        new_near_bug[0], open_bug[0], close_bug[0], close_unbug[0], add_str_dev_bug, add_str_activation_bug, total_day, now)
    # print("bug的统计汇总:"+statistics_bug)
    return statistics_bug
具体关联钉钉代码
import datetime
from dingtalkchatbot.chatbot import DingtalkChatbot, FeedLink

class ding_talk():
    def send_bug(self,url, data_file,sign_mark):#设置发送的信息样式
        '''
        :param url: 钉钉机器人的webhook
        :param data_file: 查看详情中的markdown信息
        :param sign_mark: 用户而可以自定义字段为本周、还是本月的禅道BUG情况统计
        :return:
        '''
        xiaoding = DingtalkChatbot(url)
        # Markdown消息@所有人
        now = datetime.datetime.now().strftime("%Y%m%d")
        # print("当前时间:"+str(now))
        
        # 含html
        xiaoding.send_markdown(title='BUG统计%s' % (now),
                               text='**禅道BUG情况统计**\n\n 各位同事,以下是禅道BUG情况统计。统计结果供各组组长参考,烦请做好督促,尽快处理bug!\n\n=====================\n\n {0} \n\n[查看历史遗留bug详情](http://1**.***.***:****/test/bugdetail.html) \n'.format(
                                   data_file,now), is_at_all=False)
                             data_file, now), is_at_all=False)
            
    def bug_html2(self, lis, html_file):
        """
        对查询bug明细转html文件
        :param lis
        :param html_file
        """
        """
                对查询bug明细转html文件
                :param lis
                :param html_file
                """
        conten_title = []
        for key in ( "项目名称","开始", "结束","姓名", "bug标题", "bug_id"):
            conten_title.append(key)
        a = "</th><th>".join(conten_title)
        con_title = "<tr><th>" + a + "</th></tr>"
        conten_val = ""
        con = ""
        # lis_arr = lis.fetchall()
        for i in range(0, len(lis)):
            for index, v in enumerate(lis[i]):
                if index == 0:
                    # 20231114修复字符串拼接
                    conten_val = "<tr><td>" + str(lis[i][index]) + "</td><td>"
                    # conten_val = "<tr><td>" + lis[i][index] + "</td><td>"
                    con = con + conten_val
                    continue
                con = con + str(lis[i][index]) + "</td><td>"
            con = con[0:-2] + "r>"
            con = con + "\n"
        head = """<meta charset="utf-8">
                <style type="text/css">
                table.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #9dcc7a;border-collapse: collapse;}
                table.tftable th {font-size:12px;background-color:#abd28e;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;text-align:left;}
                table.tftable tr {background-color:#ffffff;}
                table.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;}
                </style>\n<table id="tfhover" class="tftable" border="1">\n"""
        last = "</table>"
        htm = head + con_title + con + last
        with open(html_file, "w+", encoding="utf-8") as f:
            f.write(htm)

bug统计的Jenkins项目配置截图

构建触发器
源码管理
构建
构建后操作

具体实现情况如下

在这里插入图片描述

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值