tests: refactor common functionality into TestCase subclass