Improve detach unit tests