刚结束一个实时消息系统的
测试工作,总结下实现
自动化测试的流程。
项目测试中,往往一条
测试用例既要连oracle,又要连MongoDB,还要SSH到linux sever上监控log信息,为了减小手动工作量,leader要求我们将一些测试用自动化实现,每天定期运行,并把case运行状态通过邮件发给小组里每个人。
实现过程:
1. 用java实现了自动化测试工作,打成jar包。
运行完后会生成以下三个文件:
testResult.txt - 打印所有case的执行过程,将此文件作用邮件的附件发送)
emailTitle_testResult.txt - 格式为[PASSED/FAILED] - XXX Regression,根据case最近运行状态生成相应的邮件title)
emailContent_testResult.txt - 根据运行状态生成相应的邮件内容,比如:
###### SUMMARY ######
RAN: 15
PASSED: 14
FAILED: 1
Test Cases ran during this regression:
- TC1
- TC2
- TC3
The below test cases are FAILED, please find the details in the attachment.
Test case 1 - XXX
The reason of failed.
Attached is the output from each test.
Here's a wiki which holds the Test Plan, Test Cases, and explains the test cases ran:
https://xxxx
Best Regards,
QA Team
2. 在测试机上安装ant,配置环境变量,配置build.xml来运行ant发送邮件。
build_QA.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="proName" default="sendEmail" basedir=".">
<property name="mail_to" value="a valid email address"/>
<property name="mail_cc" value="a valid email address,a valid email address"/>
<property name="result.archive.dir" value="C:/QA/Result"/>
<loadfile property="contentOfTitle" srcfile="C:/QA/Result/emailTitle_testResult.txt"/>
<loadfile property="contentOfBody" srcfile="C:/QA/Result/emailContent_testResult.txt"/>
<target name="sendEmail" depends="" >
<mail mailhost="smtp.gmail.com" mailport="465"
user="username@gmail.com" password="pwd" ssl="true"
subject="${contentOfTitle}"
tolist="${mail_to}"
cclist="${mail_cc}">
<from address="username@gmail.com"/>
<message mimetype="text/html">
${contentOfBody}
</message>
<attachments>
<fileset dir="${result.archive.dir}">
<include name="testResult.txt"/>
</fileset>
</attachments>
</mail>
</target>
</project>
3. 创建批处理文件,用命令执行jar程序,运行ant发送case运行状态。
QA regression.bat文件内容如下:
@echo off
color 02
cd C:\QA
del /Q "c:\QA\Result\*.*"
java -jar xxx.jar
cd ..
ant -buildfile build_QA.xml
echo ************************************************************************************
echo Please find the result of running at the folder "c:\QA\Result\"
echo ************************************************************************************
echo Press any key to quit CMD window
pause>nul
(NOTE: 运行ant时,如果直接写命令ant不带参数, 则会在当前目录下默认运行build.xml)
4. 将QARegression.bat加到window的定时任务里,设置每天的某个时间点执行
Start > Control Panel > System and Security > Administrative Tools > Schedule tasks
Task Scheduler窗口中间右键Create New Task.
In the General tab, enter a value into Name.
In the Triggers tab, click New, select On a schedule for Begin the task, enable the Daily radio button, set up run time for Start. (Optional: Enable the Stop task if it runs longer than: checkbox.)
In the Actions tab, click New, select Start a program for Action, click the browse button to select QARegression.bat.