Add bulk tests for queries.
Add bulk tests for join queries.
Abstract common test code.