Application isolation annotation
An application state can be changed during test execution. Such changes can cause a false test failure.
The integration testing framework keeps the tests isolated and provides optimal performance by default. Isolation is managed using the @magentoAppIsolation annotation.
data-variant=info
data-slots=text
Format
Application isolation annotation:
/**
* @magentoAppIsolation enabled|disabled
*/
Test case annotation
The application and related objects are reinitialized after each test case execution. This behavior helps to isolate application objects in different test cases. The test case isolation is mandatory and cannot be disabled.
data-variant=warning
data-slots=text
Test annotation
By default, the application isolation (that is automatic reinitialization) in tests is disabled. To enable the application isolation for a test, use the @magentoAppIsolation annotation.
Example:
/**
* @magentoAppIsolation enabled
*/
public function testGetAddressById()
{
$addressId = 2;
$address = $this->repository->getById($addressId);
$this->assertEquals($this->_expectedAddresses[1], $address);
}
data-variant=info
data-slots=text
\Magento\TestFramework\TestCase\AbstractController behave as if @magentoAppIsolation is enabled for each test.Defaults
Default values for the @magentoAppIsolation annotation:
\PHPUnit\Framework\TestCase\Magento\TestFramework\TestCase\AbstractController@magentoAppIsolation cannot be disabled at the test case level.
You can use non-isolated tests unless they do not modify or utilize the same application areas such as:
- same attributes of an application object.
- same paths in a current configuration or current scope (for example "store").
data-variant=success
data-slots=text