Improved logic in unit tests