Replace multiple occurrences of  manual generation of test dir with a common utility code