Add UA lib tests and tidy up test code