Refactor test case code