AI知识分享AI知识分享
✿导航
  • 人工智能
  • 神经网络
  • 机器学习
  • 深度学习
  • 强化学习
  • 自然语言处理
  • 计算机视觉
  • 大模型基础
  • 动手学深度学习
  • 理论理解
  • 工程实践
  • 应用开发
  • AI For Everyone
  • AIGC_2024大会
  • AIGC_2025大会
  • Transformer
  • Pytorch
  • HuggingFace
  • 蒸馏
  • RAG
  • 目标检测
  • MCP
  • 概念
  • 意图识别
  • 工具
✿导航
  • 人工智能
  • 神经网络
  • 机器学习
  • 深度学习
  • 强化学习
  • 自然语言处理
  • 计算机视觉
  • 大模型基础
  • 动手学深度学习
  • 理论理解
  • 工程实践
  • 应用开发
  • AI For Everyone
  • AIGC_2024大会
  • AIGC_2025大会
  • Transformer
  • Pytorch
  • HuggingFace
  • 蒸馏
  • RAG
  • 目标检测
  • MCP
  • 概念
  • 意图识别
  • 工具
  • 意图识别

    • 应用 - 意图识别
  • 工具

    • 工具 - AI代码生成率检测工具
    • 工具 - 契约测试

契约测试

  • 安装依赖
  • 运行程序
  • 登录Pact-Broker网站
  • 具体操作过程
    • 启动Pact-Broker,支持网站访问
    • 启动Provider提供接口访问
    • 运行消费者契约测试,生成契约文件
    • 运行生产者契约测试,验证契约文件

示例:

详情

实践过程

安装依赖

sudo yum install gcc python3-devel
pip3 install pytest pact-python flask json5
pip3 install --upgrade httpcore requests

运行程序

[root@VM-0-4-centos ~]# cd /home/klc/pact_study/broker/
[root@VM-0-4-centos broker]# docker-compose up -d
...

Creating broker_postgres_1 ... done
Creating broker_broker_app_1 ... done
Creating broker_nginx_1      ... done

登录Pact-Broker网站

pactbroker/pactbroker

具体操作过程

启动Pact-Broker,支持网站访问

[root@VM-0-4-centos pact_study]# ./pact.sh start_broker
Starting Pact Broker
Creating network "broker_default" with the default driver

启动Provider提供接口访问

[root@VM-0-4-centos pact_study]# ./pact.sh start_provider
Starting Provider App
 * Serving Flask app 'user-app' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 962-565-275

运行消费者契约测试,生成契约文件

备注:

vi /etc/profile  #添加export PYTHONPATH=$PYTHONPATH:/home/klc/pact_study
source /etc/profile
[root@VM-0-4-centos pact_study]# ./pact.sh run_consumer_test
Runing Consumer Test
=============================================== test session starts ================================================
platform linux -- Python 3.6.8, pytest-7.0.1, pluggy-1.0.0
rootdir: /home/klc/pact_study/tests
plugins: anyio-3.6.2
collected 1 item

运行生产者契约测试,验证契约文件

[root@VM-0-4-centos pact_study]# ./verify_pact.sh v1 http://localhost:5001 http://localhost:5002 http://127.0.0.1:5300
最近更新: 2025/3/22 09:49
Contributors: klc407073648
Prev
工具 - AI代码生成率检测工具