更聪明地进行工作
by Brian Mitchell, Mango Solutions
芒果解决方案公司的Brian Mitchell
Here at Mango we take testing very seriously and as the automated tester in the company I take it more seriously than most.
在Mango,我们非常重视测试,作为公司的自动化测试人员,我比大多数人都更加重视测试。
Automated testing does exactly what it says on the tin, it allows you to automate a number of test scenarios. We use specialised software to simulate mouse clicks and keyboard entry and write custom scripts that can be executed on an application numerous amounts of times.
自动化测试的功能与锡盒上所说的完全一样,它使您可以自动化许多测试方案。 我们使用专门的软件来模拟鼠标单击和键盘输入,并编写可在应用程序上执行多次的自定义脚本。
My job is to try and come up with the most efficient way of testing our products before they go out the door to our customers. Working within the constraints of time and cost, I need to make things as easy as possible; I want to be able to push a button (maybe two if I’m feeling particularly energetic) and sit and watch the results roll in.
我的工作是尝试并提出最有效的方法来测试我们的产品,然后再将其交付给客户。 在时间和成本的约束下工作,我需要使事情变得尽可能简单。 我希望能够按下一个按钮(如果我感觉特别精力充沛,也许可以两个),然后坐下来观察结果。
If the tests fail I want to know why immediately, is it a test failure or is it a genuine bug. Understanding why/how it has failed quickly is extremely important. If it’s a bug then we can raise an issue and get it into the developers hand as quickly as possible.
如果测试失败,我想立即知道为什么,这是测试失败还是真正的错误。 理解为什么/如何Swift失败非常重要。 如果是错误,那么我们可以提出一个问题,并尽快将其提交开发人员手中。
To achieve this I use a number of different technologies including
为此,我使用了许多不同的技术,包括
- Jenkins (Jenkins is a continuous integration and continuous deliveryapplication)
- Python (Python is a programming language)
- TestComplete (TestComplete is the IDE for developing automated testing scripts)
- TestExecute (TestExecute executes the scripts created within TestComplete)
- Jenkins(Jenkins是一个持续集成和持续交付应用程序)
- Python(Python是一种编程语言)
- TestComplete(TestComplete是用于开发自动化测试脚本的IDE)
- TestExecute(TestExecute执行在TestComplete中创建的脚本)
When I first started to carry out automated testing, I noticed a number of inefficiencies in the process. These will be described below, along with the steps I took to resolve them.
刚开始进行自动化测试时,我注意到该过程存在许多效率低下的问题。 这些内容以及我为解决这些问题而采取的步骤将在下面进行说明。
One of the first thing noticed was that it took a long time to gather result files. This was because they were being collected manually.
注意到的第一件事是收集结果文件花了很长时间。 这是因为它们是手动收集的。
Manual collection of results seemed crazy – why do something manually when you can easily automate it? So the first thing I did was write a script to collect the result files from the various Jenkins jobs we have. This turned an hour long job into a few seconds; I then went a step further and used the XML data in Jenkins to sort the result files into folders Pass, Fail and Unstable.
手动收集结果似乎很疯狂–为什么在可以轻松实现自动化的情况下手动进行操作? 因此,我要做的第一件事是编写一个脚本,以从我们拥有的各种Jenkins作业中收集结果文件。 这把一个小时的工作变成了几秒钟。 然后,我又走了一步,使用Jenkins中的XML数据将结果文件分类为Pass,Fail和Unstable文件夹。
This made finding the results a lot quicker, but I didn’t stop there.
这样可以更快地找到结果,但我没有止步于此。
So I decided to start using the Test Complete plugin for Jenkins, this allows you to view the results files within the Jenkins console rather than opening them up separately. This saves time as well as disk space for the results files.
因此,我决定开始为Jenkins使用Test Complete插件,这使您可以在Jenkins控制台中查看结果文件,而不必单独打开它们。 这样可以节省时间以及结果文件的磁盘空间。
But I still wanted a place to go where I could view all the results in one location, so I decided to start learning Python. Python allowed me to write a script that collected the XML results and pump them into an html table, so after an execution of a suite the Python script gets executed and an overview of the results are generated into a table.
但是我仍然想要一个可以在一个位置查看所有结果的地方,所以我决定开始学习Python。 Python允许我编写一个脚本,该脚本收集XML结果并将其泵入html表,因此在执行套件后,将执行Python脚本,并将结果概述生成到表中。
Python is a high-level programming language, It was designed in such a way the code is very readable and complex tasks can be expressed in a few lines of code.
Python是一种高级编程语言,它的设计方式是使代码非常易读,并且可以用几行代码来表达复杂的任务。
The table shows me if the test passed or failed. If a failure occurs it grabs the first error message and places it in the table. This doesn’t present me with the exact issue of failure but it gives me a good idea. Each test has a hyperlink which will take you to the full results where you can then investigate why this test is failing further
该表显示了测试是否通过或失败。 如果发生故障,它将获取第一条错误消息并将其放在表中。 这不会给我带来确切的失败问题,但它给了我一个好主意。 每个测试都有一个超链接,它将带您进入完整结果,然后您可以在其中调查该测试进一步失败的原因
Collecting the results is one issue, another is execution. The previous system in Jenkins was set up using the build trigger system; this means all the jobs were put in order and locked to a node, which can be slow. This posed inefficiencies as I was unable to execute a single test easily; to do this I had to go into the config of a test and change all sorts of triggers, kick it off and then remember to change to back when it finishes.
收集结果是一个问题,另一个是执行。 Jenkins的先前系统是使用构建触发系统建立的; 这意味着所有作业都按顺序排列并锁定到一个节点上,这可能很慢。 由于我无法轻松执行单个测试,因此效率低下。 为此,我必须进入测试的配置并更改各种触发器,将其启动,然后记得在完成时将其更改为返回。
I decided to completely redesign how the tests were kicked off. I wanted to have the ability to kick off all the tests against any browser and any available test server without changing anything. This was done by separating the tests into particular groups; these groups are sorted under a root group. I won’t go into the details of how this is setup in Jenkins, but with this I can either run Test 1 on its own, execute the whole of group 1 or execute from the root which will run everything all with a few button clicks.
我决定完全重新设计测试的启动方式。 我希望能够在不更改任何内容的情况下针对任何浏览器和任何可用的测试服务器启动所有测试。 通过将测试分为特定的组来完成; 这些组在根组下排序。 我不会详细介绍如何在Jenkins中进行设置,但是我可以自己运行测试1,执行整个组1或从根目录执行,只需单击几下即可运行所有内容。
When executing a test you can decide which server you test against and which browser or you can use the defaults.
执行测试时,您可以决定要针对哪个服务器以及哪个浏览器进行测试,也可以使用默认值。
Figure 1: Old Jenkins System
图1:旧的詹金斯系统
Figure 2: New Jenkins System
图2:新的詹金斯系统
This makes it a lot easier to verify if issues have been resolved as you can only run the tests that originally found the issue to ensure it has been resolved.
这使验证问题是否已解决变得容易得多,因为您只能运行最初发现问题的测试以确保已解决问题。
Another one of my objectives was to reduce the time it took to run the entire suite; historically, it had taken more than 24 hours to run every test. This is too long for fast development.
我的另一个目标是减少运行整个套件所需的时间。 从历史上看,每次测试都花费了超过24小时的时间。 这对于快速开发来说太长了。
So with the steps I have taken as well as increasing the test slaves from 3 to 5, the tests wait in queue – allowing the tests just to wait in queue, when a slave is free the next in line is immediately started.
因此,按照我已采取的步骤以及将测试从属服务器从3个增加到5个,测试将在队列中等待-允许测试仅在队列中等待,当从属服务器空闲时,立即开始下一个队列。
This is down to around 12 hours now, so we are able to run these overnight, every night and along with the CI tests that are executed every 2 hours (they are paused when the full suite is being executed) we are pretty well covered.
现在已经减少到大约12个小时,因此我们能够在一夜之间,每天晚上以及每2个小时执行一次CI测试(在执行完整套件时暂停)的情况下运行这些程序,我们的工作范围很广。
My main aim walking into this job was to improve the process, to be able to run any test that’s required of me almost immediately (if the test exists of course), I also wanted to be able to get the results as quickly as possible.
我从事这项工作的主要目的是改进流程,几乎可以立即运行我所需要的任何测试(如果当然存在测试),我还希望能够尽快获得结果。
翻译自: https://www.pybloggers.com/2015/12/work-smarter-and-not-harder/
更聪明地进行工作