I am using this in ext_localconf.php
// Make sure "Context()->isTesting" fits or do it another way
if(Environment::getContext()->isTesting()) {
$GLOBALS['TYPO3_CONF_VARS']['HTTP']['auth'] = [
getenv('BASIC_AUTH_USER'),
getenv('BASIC_AUTH_PASSWORD'),
];
}