ci 數據庫異常捕獲_系統地捕獲錯誤:如何通過4個步驟構建GitLab CI測試管道

ci 數據庫異常捕獲

by Joyz

通過喬伊斯

系統地捕獲錯誤:如何通過4個步驟構建GitLab CI測試管道 (Catch bugs systematically: how to build a GitLab CI testing pipeline in 4 steps)

Your first app is a hit the day it’s launched. But one week later, you realize that it has no retention. You discover that this is because whenever a user clicks the “send” button, their comments get posted twice.

您的第一個應用在發布之日就很受歡迎。 但是一周后,您意識到它沒有保留。 您發現這是因為每當用戶單擊“發送”按鈕時,他們的評論都會被發布兩次。

The bug was so minor, but it killed your momentum. But that’s okay. For your second app, you and your partner check more carefully. You both click, click, click your app all day and night to prevent minor bugs like that from happening again.

該錯誤很小,但是卻扼殺了您的動力。 但是沒關系。 對于您的第二個應用程序,您和您的合作伙伴會更加仔細地檢查。 你們全天都單擊,單擊和單擊您的應用程序,以防止類似的小錯誤再次發生。

For one app, that’s okay. But after a year, you have a company building 7 apps on different platforms, including web, iOS, and Android. Your team now does code review before any app launch. You test through the apps and do your clicking before they’re shipped. But your nightmare from app #1 returns: users drop the app and this time it’s because their posts showing strange characters when they type an emoji. You end up with 1-star ratings after launch.

對于一個應用程序,沒關系。 但是一年后,您有一家公司在不同的平臺(包括Web,iOS和Android)上構建了7個應用程序。 現在,您的團隊會在任何應用啟動之前進行代碼審查。 您可以對應用進行測試,然后在發布前進行點擊。 但是您從應用程序#1的噩夢又回來了:用戶放棄了該應用程序,這次是因為他們輸入表情符號時帖子顯示奇怪的字符。 啟動后,您將獲得1星評級。

There are 3 types of product-making companies: those who do not test, those who test, and those who test fast, accurately and frequently.

產品制造公司分為3種類型:不測試的公司,測試的公司以及快速,準確且頻繁地測試的公司。

Is an automated testing system with continuous integration (CI) just a dream? CI seems like a “nice-to-have”, especially since services that run tests and generate reports like Sauce Labs, BrowserStack, Test Complete are expensive. The good news is, there are many free and popular tools out there that you can mix and match to set up a free automated testing system. As a QA tester, I figured out a free testing pipeline setup, so I’m sharing it to save you time and money.

具有持續集成(CI)的自動化測試系統只是夢想嗎? CI似乎是“必備”,特別是因為運行測試并生成諸如Sauce Labs , BrowserStack , Test Complete之類的報告的服務非常昂貴。 好消息是,這里有許多免費且流行的工具,您可以將其混合使用以建立免費的自動化測試系統。 作為質量檢查測試人員,我想出了免費的測試管道設置,因此我將其共享以節省您的時間和金錢。

Why did my company want to set up an automated system? Here are some reasons below:

我的公司為什么要建立一個自動化系統? 以下是一些原因:

  • We hate manual repetitive jobs that are prone to human error.

    我們討厭容易發生人為錯誤的手動重復性工作。
  • We want a smoother process (test it when there is a code update), and reduce the waiting time.

    我們想要一個更流暢的過程(在有代碼更新時進行測試),并減少等待時間。
  • We want to schedule the tests and make them under control.

    我們希望安排測試時間并使它們處于受控狀態。

設置您的UI測試 (Setting up your UI tests)

This post introduces a practical pipeline setup that can run web-based UI (User Interface) tests automatically and continuously. The later part maybe a bit technical but it’s quite fun to build!

這篇文章介紹了一種實用的管道設置,可以自動連續地運行基于Web的 UI(用戶界面)測試。 后面的部分可能有點技術性,但是構建起來很有趣!

I have set up the whole system with these free and open-source tools:

我已經使用以下免費和開源工具設置了整個系統:

  • Selenium — to script and automate browsers to perform tests

    Selenium-編寫腳本并自動執行瀏覽器以執行測試

  • Docker — to build an image for test environment and ship it fast

    Docker-為測試環境構建映像并快速交付

  • Gitlab CI — to trigger, build and run the test upon code updates

    Gitlab CI —在代碼更新時觸發,構建和運行測試

  • Skygear — to save test result for report on demand

    Skygear —保存測試結果以按需報告

步驟1:編寫腳本并在本地運行 (Step 1: Write the script and run it locally)

First of all, we write the test script, to let our original manual test run automatically. Selenium is a well-known tool for web automation. It supports different client languages including Java, Ruby, Python, etc.

首先,我們編寫測試腳本,以使我們原始的手動測試自動運行。 Selenium是用于Web自動化的著名工具。 它支持不同的客戶端語言,包括Java,Ruby,Python等。

Here’s an example on perform a button click on a website in Python.

這是使用Python在網站上執行按鈕單擊的示例。

Update: Added usage of Chrome official headless mode (details here).

更新:新增了Chrome官方無頭模式的用法( 在此處查看詳細信息)。

With the idea of a basic unit test model, we could easily identify these three major components in the script:

通過基本單元測試模型的思想,我們可以輕松地在腳本中識別出這三個主要組件:

  • Set up

    建立
  • Run test case

    運行測試用例
  • Tear down

    拆除

In this script, it will run test_case_1 and test_case_2 respectively, both with setUp before the test and tearDown after the test. We use unittest as our testing framework in this example. Feel free to use what you like, such as pytest or nose in Python.

在此腳本中,它將分別運行test_case_1test_case_2 ,在測試之前使用setUp ,在測試之后使用tearDown 。 在此示例中,我們使用unittest作為測試框架。 隨意使用您喜歡的東西,例如pytest或Python中的鼻子 。

You can add more test cases, such as filling in forms and clicking on elements, depending on your website's interface.

您可以添加更多測試用例,例如填寫表單和單擊元素,具體取決于您的網站界面。

步驟2:使用測試環境構建映像 (Step 2: Build an image with your testing environment)

Test running requires a clean environment. To create a clean environment, we definitely do not want to set up a real machine every time and wait for hours to install all the software needed. The container concept helps.

測試運行需要一個干凈的環境。 為了創建一個干凈的環境,我們絕對不希望每次都設置一臺真實的計算機,而是等待數小時來安裝所有需要的軟件。 容器概念會有所幫助。

Docker helps you build your testing environment into an image. The image includes all the software that needs to be pre-installed and run on that container like a virtual machine. With Docker, you can just create a new container and pull the same image every time you want to start over from your default environment.

Docker幫助您將測試環境構建到映像中。 該映像包括需要預安裝并在該容器上運行的所有軟件,例如虛擬機。 使用Docker,您每次只要要從默認環境重新開始,就可以創建一個新容器并提取相同的映像。

To perform our test with the Selenium Python client, we want our image to pre-install the following:

要使用Selenium Python客戶端執行測試,我們希望我們的映像預先安裝以下內容:

  • Python

    Python
  • Google Chrome

    谷歌瀏覽器
  • Chrome driver

    Chrome驅動
  • Xvfb

    Xvfb

Xvfb is a virtual display server that helps you to launch a browser in a headless mode (without display). It is necessary to run the UI tests in a container. It cannot connect to a display output to show the browser visually.

Xvfb是一個虛擬顯示服務器,可幫助您以無頭模式 (無顯示)啟動瀏覽器。 必須在容器中運行UI測試。 它無法連接到顯示輸出以直觀顯示瀏覽器。

Then, we will also install the Selenium package inside the container. Not all projects need the same list of packages.

然后,我們還將Selenium軟件包安裝在容器內。 并非所有項目都需要相同的軟件包列表。

We create a Dockerfile, build the image and upload to our Docker Cloud.

我們創建一個Dockerfile ,構建映像并上傳到我們的Docker Cloud 。

You could find this image through this link, or directly pull this image with this command:

您可以通過此鏈接找到該圖像,或使用以下命令直接拉出該圖像:

docker pull joyzoursky/python-chromedriver:3.6-xvfb

Then you will have an environment ready for performing the UI tests.

然后,您將為執行UI測試做好準備。

Update: Added new Docker image built with Xvfb deprecated (details here).

更新:添加了不推薦使用Xvfb構建的新Docker映像( 在此處查看詳細信息)。

第三步:設置GitLab CI (Step 3: Set up GitLab CI)

GitLab provides a CI/CD Pipelines feature, to continuously build and run your projects. The setup is like other CI tools such as Travis CI or Jenkins. This requires a .gitlab-ci.ymlfile to configure your build process.

manbetx客戶端打不開提供CI / CD管道功能,以持續構建和運行您的項目。 該設置類似于其他CI工具,例如Travis CI或Jenkins。 這需要一個.gitlab-ci.yml文件來配置您的構建過程。

Take a look at this example:

看一下這個例子:

Update: Added example with Xvfb deprecated (details here).

更新:添加了不推薦使用Xvfb的示例( 此處有詳細信息)。

When new codes are pushed to the repository, GitLab will look for .gitlab-ci.yml from the root directory, and trigger a build according to your settings.

將新代碼推送到存儲庫后,GitLab將從根目錄中查找.gitlab-ci.yml ,并根據您的設置觸發構建。

In this script, it pulls the environment image from joyzoursky/python-chromedriver:3.6-xvfb in the first line. Then it installs the required packages like Selenium, sets variables needed, and then it starts the process.

在此腳本中,它從第一行中的joyzoursky/python-chromedriver:3.6-xvfb中提取環境映像。 然后,它安裝所需的程序包(如Selenium),設置所需的變量,然后啟動該過程。

Note that there are 2 stages of the build process in this example: test and report. In each stage, the jobs in that stage will be run concurrently. You can define tests in the same stage if they could run in sync.

請注意,在此示例中,構建過程分為兩個階段: testreport 。 在每個階段中,該階段中的作業將同時運行 如果測試可以同步運行,則可以在同一階段定義測試。

Go to the Pipelines page to see the flow and completion here:

轉到“管道”頁面以查看此處的流程和完成情況:

So where do we run our tests actually?

那么,我們實際上在哪里運行測試?

GitLab hosts some shared runners which are free. By looking into the build log, we can find the container information in the first few lines:

GitLab托管了一些免費的共享跑步者。 通過查看構建日志,我們可以在前幾行中找到容器信息:

Running with gitlab-ci-multi-runner 1.10.4 (b32125f)Using Docker executor with image joyzoursky/python-chromedriver:3.5 ...Pulling docker image joyzoursky/python-chromedriver:3.5 ...Running on runner-4e4528ca-project-2749300-concurrent-0 via runner-4e4528ca-machine-1489737516-5e0de836-digital-ocean-4gb...

It shows the container name running on Digital Ocean.

它顯示了在Digital Ocean上運行的容器名稱。

Of course, you can also create your specific runners to run the test on your self-hosted machines. GitLab supports runners on different platforms including Docker and Kubernetes. But, as GitLab is a new platform, it goes through many updates. So the specific runners may sometimes break when they are out-of-date. You should always refer to the official repository when configuring the setup.

當然,您也可以創建特定的運行程序以在自托管計算機上運行測試。 GitLab在包括Docker和Kubernetes在內的不同平臺上支持跑步者。 但是,由于GitLab是一個新平臺,它需要進行許多更新。 因此,特定跑步者有時會在過時時中斷。 配置設置時,您應始終參考官方存儲庫 。

第4步:定期運行并報告 (Step 4: Run and report periodically)

You may want to have your tests run periodically. You can achieve this by setting up cron jobs, but you may not want to set up a server just to run a one-line cron job. My company’s open source serverless back-end is Skygear. We can use it to write a simple cloud code function with the @every decorator and trigger the test pipeline on an interval of time.

您可能希望定期運行測試。 您可以通過設置cron作業來實現此目的,但是您可能不希望僅運行單行cron作業來設置服務器。 我公司的開源無服務器后端是Skygear 。 我們可以使用它使用@every裝飾器編寫一個簡單的云代碼函數,并在一定時間間隔內觸發測試管道。

  • Login to your Skygear portal

    登錄到您的Skygear門戶

  • Find your Cloud Code Git URL

    查找您的Cloud Code Git URL
  • Clone the quick start codes

    克隆快速入門代碼
  • Edit to add the little piece of code below

    編輯以添加下面的一小段代碼
  • Push the codes and the cron job will trigger the test every hour

    推送代碼,cron作業將每小時觸發一次測試

Update: Used GitLab 10.0 pipeline scheduler instead of cron job (details here).

更新:使用了GitLab 10.0管道調度程序,而不是cron作業( 此處有詳細信息)。

Assume that you have already written some code to generate test reports. Would you like to receive and read the test reports every hour? Of course not. So, we also link Skygear’s free Cloud DB service to store the test result. The system only sends alerts when a test case changes from PASS to FAIL, or FAIL to PASS. This notification approach may vary according to the project need.

假設您已經編寫了一些代碼來生成測試報告。 您想每小時接收和閱讀測試報告嗎? 當然不是。 因此,我們還鏈接了Skygear的免費Cloud DB服務來存儲測試結果。 僅當測試用例從PASS更改為FAIL或從FAIL更改為PASS時,系統才會發送警報。 此通知方法可能會根據項目需求而有所不同。

To save and retrieve data from the Skygear database, we could use the existing SDK. Or if you are a Python user, you may use this little Python DB Client to help write your data handler . We use it to save test results after each test case, and retrieve the reports after running all test suites.

要從Skygear數據庫保存和檢索數據,我們可以使用現有的SDK。 或者,如果您是Python用戶,則可以使用這個小的Python DB客戶端來幫助編寫數據處理程序。 我們用它來保存每個測試用例之后的測試結果,并在運行所有測試套件后檢索報告。

Finally, we can have the test result alerts sent on demand.

最后,我們可以按需發送測試結果警報。

P.S. We use Slack real time messaging API to do the reporting, so we can receive notifications in the corresponding project channels.

PS:我們使用Slack 實時消息傳遞API進行報告,因此我們可以在相應的項目渠道中接收通知。

結論 (Conclusion)

Now, whenever there is a code update on the production branch, this automated UI test is triggered and tests are done automatically. Failure results will be pushed back to our Slack channel to notify our developers.

現在,只要生產分支上有代碼更新,就會觸發此自動UI測試并自動完成測試。 失敗結果將被推回到我們的Slack頻道,以通知我們的開發人員。

The biggest barrier to setting up a free automated UI test is probably researching the tools if you are not already a professional QA tester. Since QA is my full-time job, I hope that sharing our upgraded UI Test stack will help free up your time as well!

如果您還不是專業的QA測試人員,則設置免費的自動UI測試的最大障礙可能是研究工具。 由于質量檢查是我的全職工作,所以我希望共享升級的UI測試堆棧也將有助于您節省時間!

If you found this useful, please click the ? below so other people can see it too. Thank you!

如果您發現此功能有用,請單擊“?”。 在下方,其他人也可以看到。 謝謝!

翻譯自: https://www.freecodecamp.org/news/4-steps-to-build-an-automated-testing-pipeline-with-gitlab-ci-24ccab95535e/

ci 數據庫異常捕獲

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/395445.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395445.shtml
英文地址,請注明出處:http://en.pswp.cn/news/395445.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

(小白)函數一: 聲明函數的方法—語句定義法和表達式定義法的區別

一、函數的定義: 在說明什么是函數前先舉一個小例子: 大家都知道印刷術是我國的四大發明(科普一下:中國四大發明:造紙術、印刷術、火藥、指南針)之一,之所以有印刷術,是因為重復的抄…

android限制輸入字符的范圍,Android EditText 對輸入字數和內容范圍進行限制

在做定制機時,對光敏值進行范圍控制時,以及對區號輸入時遇到對輸入字數以及輸入內容的顯示。找了好多方法,終于找到了幾種方法其中EditText的addTextChangedListener功不可沒。例如對光敏值要在0到61之間。大于61時要在輸入框中自動變為61.代…

vue13過濾器 debounce延遲、limitBy、filterBy、orderBy

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>智能社——http://www.zhinengshe.com</title><meta name"viewport" content"widthdevice-width, initial-scale1.0, maximum…

Sass:一種CSS預處理器語言

http://sass-lang.com/ Sass是一種CSS預處理器語言&#xff0c;通過編程方式生成CSS代碼。因為可編程&#xff0c;所以操控靈活性自由度高&#xff0c;方便實現一些直接編寫CSS代碼較困難的代碼。 同時&#xff0c;因為Sass是生成CSS的語言&#xff0c;所以寫出來的Sass文件是不…

Python學習(五)列表的簡單操作

#!/usr/bin/env python#_*_coding:utf8_*_# 操作列表# for循環nbaStars [yaoming,kobe,manu,23,the klaw]for nbaStar in nbaStars: print(nbaStar)nbaStars [yaoming,kobe,manu,str(23),the klaw] # 這里有 int 對象&#xff0c;沒有title方法的for nbaStar in nbaStars:…

node seneca_使用Node.js和Seneca編寫國際象棋微服務,第3部分

node senecaFinishing up a three-part series on writing a rules engine with Seneca microservices.完成有關使用Seneca微服務編寫規則引擎的三部分系列文章。 Parts 1 & 2 of this series covered:本系列的第1部分和第2部分涉及&#xff1a; The Seneca microservice…

Android開發畫布銷毀,Android DialogFragment 在頁面銷毀下的使用方式

今天看到了一篇文章,講了DialogFragment的封裝方式(Android&#xff1a;我為何要封裝DialogFragment&#xff1f;),想到當初也為頁面銷毀后DialogFragment的回調方式頭疼了好久,看到了po主的思路,與當初自己想的不太一樣,就整理一下.如何在開發中遇到頁面銷毀的情況在android開…

視覺智能產品發布 阿里云這項世界第一的技術現在人人可用

用手機拍下朋友的相片&#xff0c;軟件會自動識別進行分類并將照片發送給朋友。這不是空想&#xff0c;利用視覺智能對手機相冊進行管理、分類和分享正逐步成為現實。在6月10日舉行的云棲大會上海峰會上&#xff0c;阿里云正式發布了“圖像識別”和“人臉識別”兩款視覺智能服務…

ViewPager中Fragment的重復創建、復用問題

在ViewPager中的Fragment的生命周期 隨著頁面的切換 當前的展示頁相鄰的頁面生命周期一直在變化 一開始 剛進入Activity時候&#xff0c;ViewPager默認初始化好前兩個Fragment&#xff08;消息和任務&#xff09; 消息 ->任務 05-09 14:47:39.593 31509-31509/tyh.com.tabl…

使用VB.net建立excel文件

Add the following code snippet on top of Form1.vb Imports Excel Microsoft.Office.Interop.Excel Public Class Form1Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickDim appXL As Excel.Application 聲明一個application對象Dim wbX…

沙盤演練工作坊-產品開發_Google認證的Android助理開發人員:考試演練

沙盤演練工作坊-產品開發by Rohan Taneja由Rohan Taneja Google認證的Android助理開發人員&#xff1a;考試演練 (Google Certified Associate Android Developer: Exam Walkthrough) UPDATE (24th July, 2018)更新(2018年7月24日) The certification exam is available agai…

linux hlist,linux內核V2.6.11學習筆記(2)--list和hlist

這兩個數據結構在內核中隨處可見,不得不拿出來單獨講講.這兩個數據結構都是為了方便內核開發者在使用到類似數據結構的時候不必自行開發(雖然不難),因此它們需要做到足夠的"通用性",也就是說,今天可以用它們做一個存放進程的鏈表,明天同樣可以做一個封裝定時器的鏈表…

14-angular.isDefined

判斷括號內的值是否存在。 格式&#xff1a; angular.isDefined(value); value: 被判斷是否存在的值。 返回值&#xff1a; true/false轉載于:https://www.cnblogs.com/ms-grf/p/6978886.html

實施工程師1分鐘即時演講_我是如何在1年內從時裝模特轉變為軟件工程師的

實施工程師1分鐘即時演講In 2015 I knew almost nothing about coding. Today, I’m a software engineer and a teacher at a code school for kids.在2015年&#xff0c;我對編碼幾乎一無所知。 今天&#xff0c;我是一名軟件工程師&#xff0c;還是一所代碼學校的兒童老師。…

MSSQL分組取后每一組的最新一條記錄

數據庫中二張表&#xff0c;用戶表和獎金記錄表&#xff0c;獎金記錄表中一個用戶有多條信息&#xff0c;有一個生效時間&#xff0c;現在要查詢&#xff1a; 獎金生效時間在三天前&#xff0c;每個用戶取最新一條獎金記錄&#xff0c;且用戶末鎖定 以前用的方法是直接寫在C#代…

android模擬器插件,Android模擬器插件找不到android SDK

首先&#xff0c;克隆項目詹金斯一直輸出后&#xff1a;[android] No Android SDK found; lets install it automatically...[android] Going to install required Android SDK components...[android] Installing the platform-tool,tool SDK component(s)...$ /var/lib/jenki…

讀書筆記--模板與泛型編程

了解隱式接口和編譯期多態 編譯期多態和運行期多態 運行期多態就好比是virtual函數再運行的時候才確定該virtual函數該被綁定為哪個函數&#xff0c;運行的時候才確定函數類型。  編譯期多態就好比是泛型編程和模板編程中&#xff0c;在編譯的時候才確定哪個函數該被調用&…

棧和遞歸的關系 144:Binary Tree Preorder Traversal

前序遍歷&#xff1a;根左右 //用棧來實現非遞歸解法/*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/ class Solution { public:vec…

運行級別

ls -l /usr/lib/system/runlevel*target &#xff08;查看運行級別&#xff09;Linux系統有7個運行級別(runlevel)運行級別0&#xff1a;系統停機狀態&#xff0c;系統默認運行級別不能設為0&#xff0c;否則不能正常啟動運行級別1&#xff1a;單用戶工作狀態&#xff0c;roo…

微信sdk swift版_使用Swift 4的iOS版Google Maps SDK終極指南

微信sdk swift版by Dejan Atanasov通過Dejan Atanasov 使用Swift 4的iOS版Google Maps SDK終極指南 (Your ultimate guide to the Google Maps SDK on iOS, using Swift 4) Many iOS apps use Google Maps. This is a very common feature, so I have decided to prepare an u…