【发布时间】:2021-09-03 06:29:45
【问题描述】:
我最近在我的旧应用上实现了集成测试,我对在集成测试中进行断言感到困惑。
在单元测试中,我们可以轻松地模拟对象,并且每次测试只有 1 个断言是有意义的。但是当它变成集成测试时,我想验证多个场景,需要检查每一步是否正确。
可以做多个断言吗?还是有一些最佳做法可以做到这一点?
这是我的测试代码:
def test_new_requested_depth_purchase_create_transaction(
self,
requested_depth_purchase_request_1: DepthPurchaseRequestViewModel,
):
"""depth_purchase_created_job() should create new lead,transaction and depth transaction package"""
self._depth_purchase_request_service.depth_purchase_created_job(
requested_depth_purchase_request_1.original_id
)
crm_depth_purchase = self._depth_purchase_repo.get_by_original_id(
requested_depth_purchase_request_1.original_id
)
assert crm_depth_purchase is not None
lead = self._lead_repo.get_by_id(crm_depth_purchase.leads_id)
assert lead is not None
transaction = self._transaction_repo.get_by_lead_id(lead.id)
assert transaction is not None
transaction_packages = self._transaction_package_repo.get_all_by_transaction_id(
transaction.id
)
assert len(transaction_packages) > 0
assert all(
[
trx_package.type == ProductPackageConstants.ALACARTE
and trx_package.status_id == 0
for trx_package in transaction_packages
]
)
测试框架:Pytest
【问题讨论】:
标签: python pytest integration-testing