利用Jenkins自动化服务器实现自动化测试,可以按照以下步骤进行:
pip install pytest requests
# test_api.py
import requests
BASE_URL = "https://jsonplaceholder.typicode.com"
def test_get_posts():
response = requests.get(f"{BASE_URL}/posts")
assert response.status_code == 200
assert len(response.json()) > 0
def test_get_post():
response = requests.get(f"{BASE_URL}/posts/1")
assert response.status_code == 200
assert response.json()['id'] == 1
def test_create_post():
data = {"title": 'foo', "body": 'bar', "userId": 1}
response = requests.post(f"{BASE_URL}/posts", data=data)
assert response.status_code == 201
assert response.json()['title'] == 'foo'
def test_update_post():
data = {"id": 1, "title": 'updated title', "body": 'updated body', "userId": 1}
response = requests.put(f"{BASE_URL}/posts/1", data=data)
assert response.status_code == 200
assert response.json()['title'] == 'updated title'
def test_delete_post():
response = requests.delete(f"{BASE_URL}/posts/1")
assert response.status_code == 200
pytest test_api.py
通过以上步骤,可以实现利用Jenkins自动化服务器进行自动化测试。根据具体需求,可以选择不同的测试框架和插件来扩展功能。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。