Unit test framework

Ready to merge new features back.