how to write testcase with factory