实训第二天总结

今天主要是对python的基础语法的学习和,pytest的测试文件的书写和allure的应用。

以下是我的一个测试代码

import allure

import zuoye
import pytest
# 首先在本目录下打开Terminal
# 之后使用命令:allure serve ./report/zuoye_res 可查看运行报告
# 初始化library
library = zuoye.Library()


# 测试新增图书  两条错误数据,三条正确数据
@allure.title("新增方法测试")
@pytest.mark.parametrize("title,price,intro", [["python", 115, "ww"],
                                               ["java", 16, "ww"],
                                               ["HTML", 16, "ww"],
                                               ["C", 16, "ww"],
                                               ["C++12345678", 18, "ww"]])
def test_add_book(title, price, intro):
    try:
        str = library.add_book(title, price, intro)
    except:
        str = "错误"
    assert str == f"图书《{title}》已添加。", "书名长度必须在1到10个字符之间,价格必须在0到100之间。"


# 测试更新图书,四条数据,其中三条正确数据,一条错误数据
@allure.title("修改方法测试")
@pytest.mark.parametrize("old_title,new_title,new_price,new_intro",
                         [["java", "JAVA", None, None],
                          ["HTML", "html", 20, "ee"],
                          ["C", "C语言", 25, "cc"],
                          ["不存在的书名", "ww", 20, "ee"]])
def test_update_book(old_title, new_title, new_price, new_intro):
    str = library.update_book(old_title, new_title, new_price, new_intro)
    assert str == f"图书《{old_title}》的信息已更新。", f"未找到书名为《{old_title}》的图书。"


# 测试查询模块,三条正确数据,一条错误数据
@allure.title("查询方法测试")
@pytest.mark.parametrize("title, price",
                         [["JAVA", None],
                          ["html", 20],
                          [None, 25],
                          ["不存在的书名", None]])
def test_search_book(title, price):
    res = library.search_book(title, price)
    assert len(res) == 1


# 测试删除模块,三条正确数据,一条错误数据
@allure.title("删除方法测试")
@pytest.mark.parametrize("title", ["JAVA", "html", "C语言", "不存在的title"])
def test_delete_book(title):
    str = library.delete_book(title)
    assert str == f"图书《{title}》已删除。", f"未找到书名为《{title}》的图书。"

 

posted @ 2024-06-25 20:07  一个小虎牙  阅读(6)  评论(0编辑  收藏  举报