Refactor functions tests to be less fragile, more focused and reduce test duplication