How do you typically TDD aspects of your application that need to access operating system's system variables?
For example, my application needs to be able to correctly retrieve the operating system's currently-logged-in user name.
So I TDD a function that does this, and it's called:
string getUserNameFromSystemEnvironment();
The problem that I have is:
I'm running the test on my machine, so I know what the user name is (say FooBar
). I TDD getUserNameFromSystemEnvironment()
by hardcoding FooBar
in my test like.
EXPECT_EQ(getUserNameFromSystemEnvironment(), "FooBar");
Clearly, this test runs okay on my machine, but not on others. To make it run fine on
others, however, I would need to use getUserNameFromSystemEnvironment()
. But then, that kind of defeats the purpose of the test because we will have:
EXPECT_EQ(getUserNameFromSystemEnvironment(),
getUserNameFromSystemEnvironment());
Any ideas?