refactor test code to make it shorter