{"id":20408,"date":"2024-11-19T16:09:41","date_gmt":"2024-11-19T08:09:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/20408\/"},"modified":"2024-11-19T16:09:41","modified_gmt":"2024-11-19T08:09:41","slug":"gitlab%e7%9a%84%e9%9b%86%e6%88%90%e6%b5%8b%e8%af%95%e5%8a%9f%e8%83%bd%e5%8f%8a%e5%b8%b8%e8%a7%81%e7%94%a8%e4%be%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/20408\/","title":{"rendered":"GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u53ca\u5e38\u89c1\u7528\u4f8b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/164\/169785659915137.jpg\" class=\"aligncenter\" title=\"GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u53ca\u5e38\u89c1\u7528\u4f8b\u63d2\u56fe\" alt=\"GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u53ca\u5e38\u89c1\u7528\u4f8b\u63d2\u56fe\" \/><\/p>\n<p>GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u53ca\u5e38\u89c1\u7528\u4f8b<\/p>\n<p>\u3010\u5f15\u8a00\u3011<br \/>\u5728\u8f6f\u4ef6\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6d4b\u8bd5\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u73af\u8282\u4e4b\u4e00\u3002\u5728\u6301\u7eed\u96c6\u6210\u548c\u6301\u7eed\u4ea4\u4ed8\u7684\u5f00\u53d1\u73af\u5883\u4e0b\uff0c\u96c6\u6210\u6d4b\u8bd5\u8d77\u5230\u4e86\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002\u800cGitLab\u4f5c\u4e3a\u5e7f\u53d7\u6b22\u8fce\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u4e0d\u4ec5\u63d0\u4f9b\u4e86\u7248\u672c\u7ba1\u7406\u548c\u534f\u4f5c\u5de5\u5177\uff0c\u540c\u65f6\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecdGitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\uff0c\u5e76\u63d0\u4f9b\u5e38\u89c1\u7684\u6d4b\u8bd5\u7528\u4f8b\u548c\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u3010GitLab\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u3011<br \/>GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u662f\u901a\u8fc7GitLab CI\/CD\uff08\u6301\u7eed\u96c6\u6210\/\u6301\u7eed\u4ea4\u4ed8\uff09\u529f\u80fd\u6765\u5b9e\u73b0\u7684\u3002GitLab CI\/CD\u5229\u7528.gitlab-ci.yml\u6587\u4ef6\u6765\u5b9a\u4e49\u548c\u914d\u7f6epipeline\uff0c\u5b9e\u73b0\u81ea\u52a8\u5316\u6d4b\u8bd5\u3002\u4e3b\u8981\u7684\u6d4b\u8bd5\u4efb\u52a1\u5305\u62ec\u6784\u5efa\u3001\u6d4b\u8bd5\u3001\u90e8\u7f72\u548c\u76d1\u63a7\u7b49\u3002<\/p>\n<p>\u3010\u5e38\u89c1\u96c6\u6210\u6d4b\u8bd5\u7528\u4f8b\u3011<\/p>\n<ol>\n<li>\n<p>\u5355\u5143\u6d4b\u8bd5\uff08Unit Test\uff09<br \/>\u5355\u5143\u6d4b\u8bd5\u662f\u5bf9\u8f6f\u4ef6\u4e2d\u6700\u5c0f\u53ef\u6d4b\u5355\u5143\u8fdb\u884c\u6d4b\u8bd5\u3002\u5728GitLab\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u7f16\u7a0b\u8bed\u8a00\u7684\u6d4b\u8bd5\u6846\u67b6\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528JUnit\u6765\u7f16\u5199Java\u7a0b\u5e8f\u7684\u5355\u5143\u6d4b\u8bd5\u4ee3\u7801\u3002<\/p>\n<pre>import org.junit.Assert;\nimport org.junit.Test;\n\npublic class CalculatorTest {\n\n    @Test\n    public void testAdd() {\n        Calculator calculator = new Calculator();\n        int result = calculator.add(2, 3);\n        Assert.assertEquals(5, result);\n    }\n\n    @Test\n    public void testSubtract() {\n        Calculator calculator = new Calculator();\n        int result = calculator.subtract(5, 2);\n        Assert.assertEquals(3, result);\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\n<p>\u96c6\u6210\u6d4b\u8bd5\uff08Integration Test\uff09<br \/>\u96c6\u6210\u6d4b\u8bd5\u662f\u5bf9\u591a\u4e2a\u7ec4\u4ef6\u6216\u6a21\u5757\u4e4b\u95f4\u7684\u4ea4\u4e92\u884c\u4e3a\u8fdb\u884c\u6d4b\u8bd5\u3002\u5728GitLab\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Selenium\u7b49\u6d4b\u8bd5\u5de5\u5177\u8fdb\u884c\u96c6\u6210\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Selenium\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Web\u5e94\u7528\u7a0b\u5e8f\u7684\u96c6\u6210\u6d4b\u8bd5\u4ee3\u7801\u3002<\/p>\n<pre>from selenium import webdriver\nfrom selenium.webdriver.common.keys import Keys\n\ndriver = webdriver.Firefox()\ndriver.get(\"http:\/\/www.google.com\")\n\nelement = driver.find_element_by_name(\"q\")\nelement.send_keys(\"GitLab\")\nelement.send_keys(Keys.RETURN)\n\nassert \"GitLab\" in driver.title\n\ndriver.close()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\n<p>\u6027\u80fd\u6d4b\u8bd5\uff08Performance Test\uff09<br \/>\u6027\u80fd\u6d4b\u8bd5\u662f\u5bf9\u8f6f\u4ef6\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u6027\u80fd\u8fdb\u884c\u8bc4\u4f30\u548c\u9a8c\u8bc1\u3002\u5728GitLab\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528JMeter\u7b49\u6027\u80fd\u6d4b\u8bd5\u5de5\u5177\u8fdb\u884c\u6027\u80fd\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528JMeter\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Web\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u6d4b\u8bd5\u8ba1\u5212\u3002<\/p>\n<pre>Test Plan\n\u251c\u2500 Thread Group\n\u2502     \u2514\u2500 HTTP Request (GET http:\/\/www.example.com)\n\u251c\u2500 Listeners\n\u2502     \u2514\u2500 Summary Report<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\n<p>API\u6d4b\u8bd5\uff08API Test\uff09<br \/>API\u6d4b\u8bd5\u662f\u9488\u5bf9\u5e94\u7528\u7a0b\u5e8f\u63a5\u53e3\u7684\u529f\u80fd\u548c\u6027\u80fd\u8fdb\u884c\u6d4b\u8bd5\u3002\u5728GitLab\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Postman\u7b49\u5de5\u5177\u8fdb\u884cAPI\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Postman\u7f16\u5199\u4e00\u4e2a\u6d4b\u8bd5GitLab API\u7684\u811a\u672c\u3002<\/p>\n<pre>const postmanUrl = 'https:\/\/api.postman.com';\nconst apiKey = 'your_api_key';\n\npm.test(\"Successful response\", function () {\n    pm.expect(pm.response.code).to.equal(200);\n    pm.expect(pm.response.json().success).to.be.true;\n});\n\npm.sendRequest(postmanUrl + '\/api\/collections\/' + collectionUid, function (err, response) {\n    pm.expect(response.code).to.equal(200);\n    pm.expect(response.json().success).to.be.true;\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<p>\u3010\u603b\u7ed3\u3011<br \/>\u901a\u8fc7GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\u3001\u96c6\u6210\u6d4b\u8bd5\u3001\u6027\u80fd\u6d4b\u8bd5\u548cAPI\u6d4b\u8bd5\u7b49\u5404\u79cd\u7c7b\u578b\u7684\u6d4b\u8bd5\u3002\u4e0a\u8ff0\u63d0\u4f9b\u7684\u5e38\u89c1\u6d4b\u8bd5\u7528\u4f8b\u548c\u4ee3\u7801\u793a\u4f8b\u53ea\u662f\u4e00\u90e8\u5206\uff0c\u5b9e\u9645\u5e94\u7528\u4e2d\u8fd8\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u8fdb\u884c\u66f4\u591a\u7684\u5b9a\u5236\u5316\u6d4b\u8bd5\u3002\u96c6\u6210\u6d4b\u8bd5\u7684\u6301\u7eed\u8fd0\u884c\u548c\u7ed3\u679c\u5c55\u793a\uff0c\u4e3a\u5f00\u53d1\u56e2\u961f\u63d0\u4f9b\u4e86\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3001\u53ca\u65f6\u4fee\u590dbug\u7684\u80fd\u529b\uff0c\u4ece\u800c\u63d0\u9ad8\u8f6f\u4ef6\u8d28\u91cf\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fGitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u53ca\u5e38\u89c1\u7528\u4f8b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u53ca\u5e38\u89c1\u7528\u4f8b \u3010\u5f15\u8a00\u3011\u5728\u8f6f\u4ef6\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6d4b\u8bd5\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u73af\u8282\u4e4b\u4e00\u3002\u5728\u6301\u7eed\u96c6\u6210\u548c\u6301\u7eed\u4ea4\u4ed8\u7684\u5f00\u53d1\u73af\u5883\u4e0b\uff0c\u96c6\u6210\u6d4b\u8bd5\u8d77\u5230\u4e86\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002\u800cGitLab\u4f5c\u4e3a\u5e7f\u53d7\u6b22\u8fce\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u4e0d\u4ec5\u63d0\u4f9b\u4e86\u7248\u672c\u7ba1\u7406\u548c\u534f\u4f5c\u5de5\u5177\uff0c\u540c\u65f6\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecdGitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\uff0c\u5e76\u63d0\u4f9b\u5e38\u89c1\u7684\u6d4b\u8bd5\u7528\u4f8b\u548c\u4ee3\u7801\u793a\u4f8b\u3002 \u3010GitLab\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u3011GitLab\u7684\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u662f\u901a\u8fc7GitLab CI\/CD\uff08\u6301\u7eed\u96c6\u6210\/\u6301\u7eed\u4ea4\u4ed8\uff09\u529f\u80fd\u6765\u5b9e\u73b0\u7684\u3002GitLab CI\/CD\u5229\u7528.gitlab-ci.yml\u6587\u4ef6\u6765\u5b9a\u4e49\u548c\u914d\u7f6epipeline\uff0c\u5b9e\u73b0\u81ea\u52a8\u5316\u6d4b\u8bd5\u3002\u4e3b\u8981\u7684\u6d4b\u8bd5\u4efb\u52a1\u5305\u62ec\u6784\u5efa\u3001\u6d4b\u8bd5\u3001\u90e8\u7f72\u548c\u76d1\u63a7\u7b49\u3002 \u3010\u5e38\u89c1\u96c6\u6210\u6d4b\u8bd5\u7528\u4f8b\u3011 \u5355\u5143\u6d4b\u8bd5\uff08Unit Test\uff09\u5355\u5143\u6d4b\u8bd5\u662f\u5bf9\u8f6f\u4ef6\u4e2d\u6700\u5c0f\u53ef\u6d4b\u5355\u5143\u8fdb\u884c\u6d4b\u8bd5\u3002\u5728GitLab\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u7f16\u7a0b\u8bed\u8a00\u7684\u6d4b\u8bd5\u6846\u67b6\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528JUnit\u6765\u7f16\u5199Java\u7a0b\u5e8f\u7684\u5355\u5143\u6d4b\u8bd5\u4ee3\u7801\u3002 import org.junit.Assert; import org.junit.Test; public class CalculatorTest { @Test public void testAdd() { Calculator calculator = new Calculator(); int result = calculator.add(2, 3); Assert.assertEquals(5, result); } @Test public void testSubtract() { Calculator calculator = new Calculator(); int result = calculator.subtract(5, 2); Assert.assertEquals(3, result); } } \u767b\u5f55\u540e\u590d\u5236 \u96c6\u6210\u6d4b\u8bd5\uff08Integration [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-20408","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/20408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=20408"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/20408\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=20408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=20408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=20408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}