Further refactor tests

Use random strings instead of hard-coded strings. Improve error message
handling.