Integration Test Assertion Best Practice

  integration-testing, pytest, python

I recently implemented integration tests on my legacy app, i get confused whe do assertion in Integration Test.

in unit test we can easily mock object and its make sense to only have 1 assertion every test. but when it becomes Integration Test, I want to verify the behavior and need to check every step is correct.

is it okay to do multiple assertions ? or is there some best practice to do this ?

here is my test code :

   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
            ]
        )

Test Framework : Pytest

Source: Python Questions

LEAVE A COMMENT