Improved test listener handling with less code duplication