Refactoring generate_testcase a bit with a view to sharing Context for future benchmarking code.