There have been many, many answers to the question about differences between static readonly
and const
. I am not asking about that. What I want to know is whether one or the other has a clear advantage when creating dummy data for a unit test class.
Here's an example with const
:
[TestClass]
public class CustomerModelTest
{
private const string firstName = "Bill";
private const string lastName = "The Tester";
// Test methods in the class then use the above data in their tests.
}
Here's the same example with static readonly
:
[TestClass]
public class CustomerModelTest
{
private static readonly string firstName = "Bill";
private static readonly string lastName = "The Tester";
// Test methods in the class then use the above data in their tests.
}
My team is in a debate over this question and I'd like to create a standard that would allow us to tell new hires, "Use [const/static readonly] as a default for holding dummy data, unless you have a good reason not to."
Here's what I understand so far:
const
is theoretically faster.static readonly
keeps me from having to recompile any dlls that reference the current assembly.const
cannot be used for computed values.
So are there any fact-based reasons why one is preferable to the other in this situation? Or should our team just create an arbitrary standard?