There is an ongoing debate about the following property, and if it should be tested or not. We're working in C#.
MyClass prop => value;
Should I be writing the following unit test :
IMyClass _viewModel = new MyClass();
Mock value = new Mock<Bar>();
Assert.AreEqual(value, _viewModel.Prop);
Personally, I say YES, because that property is still public, visible in the interface IMyClass
, and is a simple requirement, like many others. Because of this, its initial state should be tested. In this case, that's its only state, but that is irrelevant.
Also, the object might change and become
MyClass prop => value + othervalue;
And slowly becomes more intelligent. I believe you need to be future proof, and more importantly, simply being 100% certain of the initial state of your objects.
Now, on the other hand, the opposite opinion goes as follows :
You're over testing, what you're essentially testing is if (true == true), because that property is not going to change, and it makes the test useless.
We can't find an agreement, does anyone have some knowledge or wisdom to share?
Also, I must be fully fair, we're talking about testing Colors in this very specific case, that means checking that _viewmodel.backgroundcolor
is indeed _theme.defaultBackgroundColor
, or, like they like to say white == white
, and like I say whiteTodayButMaybeRedOrGreenTomorrow == white
.