fix a bug in the test and refactor the testing codes