Let’s assume I have a class with some similar properties:
public string First { get; set; }
public string Second { get; set; }
public string Third { get; set; }
I want to test them in the same way in my tests… So I write:
[Test]
public void TestFirst()
{
// Asserting strings here
}
Is there a way to avoid creating three Tests (one for First, one for Second and one for Third)?
I’m looking for something like [Values(First, Second, Third)], so i can then write one test that will iterate through the properties.
Cheers, and thanks in advance 🙂
Thanks all for your answers and help. Learned plenty of things.
Here’s what I’ve ended up doing. I’ve used reflection to get all the string properties, and then set to a value, check value is set, set to null, check to see it returns an empty string (logic in property’s getter).
This way I don’t need to be concerned if someone adds a property, since it’ll be checked automatically, without me needing to update the test code (as you might guess, not everybody updates nor writes tests 🙂
Any comments on this solution will be welcomed.