Refactor two previous test introductions to add a test builder

Not sure why there are so many changes here. The last commit contains the refactoring.