Test coverage is important when refactoring code to ensure that the refactored code still behaves the same way as before. Tests should cover what the function does, not how it does it.