Refactor tests

Use a base class with common factory methods.