Refactor selection tests for better isolation.

Fixes #939.