Magento – Magento 2 Integration Tests issue for custom attributes

integration-testmagento2

I have created 2 new product attributes that are mandatory (required),
"vendor_id" and "delivery_country".

After creating this two attributes the integration tests are failing.

I executed the testes just for one module to see what is happening:

<directory suffix="Test.php">testsuite/Magento/AdvancedCheckout</directory>

When running the integrations tests for this module it gives me fatal error:

Magento\AdvancedCheckout\Controller\CartTest::testConfigureFailedActionWithDownloadableProduct

Magento\Eav\Model\Entity\Attribute\Exception: The value of attribute
"vendor_id" must be set in
/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:111

I have noticed that this module is using this two files for products:

dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable.php

and

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php

I added the new attributes in the above files, after executing tests again they are passing.

The problem is that there are many files that are creating products for integration tests and I don't see as a solution to modify this files.

Is there a way to set this new attributes on all the products that are created for integration tests without modifying all the fixture files.

Best Answer

You cannot run the core test suite with a customized build like this. But this is not their purpose anyways. The core integration test suite is there to ensure that the core modules work together as intended and to prevent bugs in Magento itself.

If you want to run an integration test for the checkout that is adapted to your changes, you are free to reuse parts of the core tests, but you will have to make adjustments like adding values for custom required attributes in the used fixtures.

But do not try to recreate integration tests just for core functionality. Create tests that ensure, that your code works.

For high level "Magento still works" tests, functional tests are more appropiate than integration tests. That's also why the new Magento Functional Test Framework (MFTF) will give us extensible core tests. This one is meant to be run on custom builds.