Improved the testing framework so that common code is in different file. Generalized it a bit