Remove use of globals when non-intrusively setting up test environment and add use of test events.