Refactored handling of test client context