I like to keep my unit tests pretty simple and easy to follow. I often hardcode the expected results of a test in order to avoid repeating the code that I am testing. In addition, I often use data-driven tests. For example, if I am testing the format that a date/time is presented as, I will sometimes hard-code the expected string, ie. “1/1/2000” or “1:00 PM”. However, since date and time formats are culture-specific and our app is localizable, the actual output COULD vary. However, my team is based in the U.S. and so this is usually not a problem. Our continuous integration and build servers run with U.S. culture info as well.
There is a team member who has complained because he has changed the date format on his dev machine to manually test other date formats, and so many tests fail for him. Should I be using the current culture information when testing outputs in unit tests, or is this hard-coding acceptable?
UPDATE: I ended up setting a specific locale for certain tests.
Unit tests should be 100% repeatable, regardless of the environment in which they run. The only reason for a unit test to start failing is because the code changed and broke the test.
So yes, you need to take steps to ensure that your tests continue to pass regardless of external factors.