<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # API測試 API(Application Programming Interface)測試的自動化是軟件測試最基本的一種類型。從本質上來說,API測試是用來驗證組成軟件的那些單個方法的正確性,而不是測試整個系統本身。API測試也稱為單元測試(Unit Testing)、模塊測試(Module Testing)、組件測試(Component Testing)以及元件測試(Element Testing)。從技術上來說,這些術語是有很大的差別的,但是在日常應用中,你可以認為它們大致相同的意思。它們背后的思想就是,必須確定系統中每個單獨的模塊工作正常,否則,這個系統作為一個整體不可能是正確的。毫無疑問,API測試對于任何重要的軟件系統來說都是必不可少的。 我們對API測試的定位是服務對外輸出的API接口測試,屬于黑盒、偏重業務的測試步驟。 看過上一章內容的朋友還記得[lua-resty-test](https://github.com/membphis/lua-resty-test),我們的API測試同樣是需要它來完成。get_client_tasks是終端用來獲取當前可執行任務清單的API,我們用它當做例子給大家做個介紹。 > nginx conf: ~~~ location ~* /api/([\w_]+?)\.json { content_by_lua_file lua/$1.lua; } location ~* /unit_test/([\w_]+?)\.json { lua_check_client_abort on; content_by_lua_file test_case_lua/unit/$1.lua; } ~~~ > API測試代碼: ~~~ -- unit test for /api/get_client_tasks.json local tb = require "resty.iresty_test" local json = require("cjson") local test = tb.new({unit_name="get_client_tasks"}) function tb:init( ) self.mid = string.rep('0',32) end function tb:test_0000() -- 正常請求 local res = ngx.location.capture( '/api/get_client_tasks.json?mid='..self.mid, { method = ngx.HTTP_POST, body=[[{"type":[1600,1700]}]] } ) if 200 ~= res.status then error("failed code:" .. res.status) end end function tb:test_0001() -- 缺少body local res = ngx.location.capture( '/api/get_client_tasks.json?mid='..self.mid, { method = ngx.HTTP_POST } ) if 400 ~= res.status then error("failed code:" .. res.status) end end function tb:test_0002() -- 錯誤的json內容 local res = ngx.location.capture( '/api/get_client_tasks.json?mid='..self.mid, { method = ngx.HTTP_POST, body=[[{"type":"[1600,1700]}]] } ) if 400 ~= res.status then error("failed code:" .. res.status) end end function tb:test_0003() -- 錯誤的json格式 local res = ngx.location.capture( '/api/get_client_tasks.json?mid='..self.mid, { method = ngx.HTTP_POST, body=[[{"type":"[1600,1700]"}]] } ) if 400 ~= res.status then error("failed code:" .. res.status) end end test:run() ~~~ nginx output: ~~~ 0.000 [get_client_tasks] unit test start 0.001 \_[test_0000] PASS 0.001 \_[test_0001] PASS 0.001 \_[test_0002] PASS 0.001 \_[test_0003] PASS 0.001 [get_client_tasks] unit test complete ~~~ 使用capture來模擬請求,其實是不靠譜的。如果我們要完全100%模擬客戶請求,這時候就要使用第三方cosocket庫,例如[lua-resty-http](https://github.com/pintsized/lua-resty-http),這樣我們才可以完全指定http參數。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看