testing – Test extending BrowserTestBase failed in hook_entity_bundle_field_info_alter


My module implements the following hook:

function my_moduke_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
  $fields('field_my_field')->addConstraint('MyConstraint', ());
}

field_my_field does exists and everything runs fine except when I am trying to run a test:

1) DrupalTeststxs8FunctionalBasicTestCase::testMyTest
Undefined index: field_my_field

Followed by the line number pointing to my_moduke_entity_bundle_field_info_alter

This error is trigered when the test is running parent::setUp(); >> installDrupal() >> $this->installModulesFromClassProperty($container);… at the very begining