[Test]
public void SimpleFlatten()
{
// arrange
var sentences = new List<string> { "Hello World", "Goodbye World" };
// act
var result = sentences.SelectMany(n => n.Split(' '));
// assert
Assert.That(result.Count(), Is.EqualTo(4));
}
Would testing the count of the result be plentiful here do you think?
Having thought about this logically, I feel as though checking the count should be enough because I have no reasonable suspicion that the SelectMany
method will ever return the correct number unless the method is working correctly.
I am new to TDD however and wonder if being explicit like this would be a better practice?
CollectionAssert.AreEquivalent(
new[] { "Hello", "World", "Goodbye", "World" }, result);
Try to put yourself in the position of person reading this test 6 months from now. Which test carries more information?
Given collection of two sentences, "Hello World" and "Goodbye World"
Which one tells you more about the purpose of the method or what the method does? From TDD standpoint, you should prefer to go for less ambiguous tests, which in this case is second one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With