如何通過Debian實現Swagger自動化測試

如何通過Debian實現Swagger自動化測試

debian系統上實現Swagger自動化測試可以按照以下步驟操作:

1. 安裝Swagger

確保Debian系統的軟件包列表是最新的,接著安裝Swagger。具體命令如下:

sudo apt update sudo apt install -y curl curl -L https://github.com/swagger-api/swagger-ui/archive/master.zip -o swagger-ui.zip unzip swagger-ui.zip sudo mv swagger-ui/* /usr/share/nginx/html/ sudo rm -rf swagger-ui.zip

2. 配置Swagger

在你的spring Boot項目里,將springfox-boot-starter依賴添加到pom.xml文件中:

<dependency><groupid>io.springfox</groupid><artifactid>springfox-boot-starter</artifactid><version>3.0.0</version></dependency>

隨后,在application.yml文件里設置Swagger:

springfox:   documentation:     swagger-ui:       enabled: true

3. 啟動項目并瀏覽Swagger UI

啟動spring boot項目后,在瀏覽器中訪問http://localhost:8080/swagger-ui/,應該可以看到Swagger自動生成的文檔頁面。

4. 利用Swagger UI進行測試

在Swagger UI界面上,所有API接口都會顯示出來。選擇任一接口,填入所需參數,點擊“try it out”按鈕即可在瀏覽器中直接測試此接口。

5. 使用腳本進行快速掃描

也可以運用swagger-hacker.py腳本執行快速的接口掃描。先從github下載該腳本,再以如下命令執行:

python .swagger-hack2.0.py -u https://xxxx/swagger/v1/swagger.json

此腳本會對API進行快速掃描,并生成測試記錄。

6. 集成持續集成工具(如jenkins

在Jenkins中創建一個新的任務,配置任務的構建步驟,運行自動化測試腳本。例如:

pytest /path/to/your/test_api.py

通過以上步驟,你就能在Debian系統上借助Swagger完成自動化測試,進而提升開發與測試效率。

? 版權聲明
THE END
喜歡就支持一下吧
點贊14 分享