Edit in GitHubLog an issue

Application isolation attribute

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 AppIsolation attribute.

Format

Copied to your clipboard
#[
AppIsolation(bool $state = true)
]

Parameters

  • state
    • Accepts TRUE or FALSE to enable or disable app isolation respectively.

Test class attribute

The application and related objects are reinitialized after each test class execution. This behavior helps to isolate application objects in different test classes. The test class isolation is mandatory and cannot be disabled.

Test method

By default, the application isolation (that is automatic reinitialization) in tests method is disabled. To enable the application isolation for a test method, use the AppIsolation attribute.

Example:

Copied to your clipboard
#[
AppIsolation(true)
]
public function testGetAddressById()
{
$addressId = 2;
$address = $this->repository->getById($addressId);
$this->assertEquals($this->_expectedAddresses[1], $address);
}

Defaults

Default values for the AppIsolation attribute:

Test class ancestorsTest classTest method
\PHPUnit\Framework\TestCase
enabled
disabled
\Magento\TestFramework\TestCase\AbstractController
enabled
enabled

AppIsolation cannot be disabled at the test class 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").
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.