Do I have to approve the score or result explicitly?

[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));
}

Will the number of results be checked here?

Thinking logically about this, I feel that checking the account should be sufficient, because I have no reasonable suspicion that the method SelectManywill ever return the correct number if the method works correctly.

I am new to TDD and wondering if it will be more explicit, like this, better?

CollectionAssert.AreEquivalent(
    new[] { "Hello", "World", "Goodbye", "World" }, result);
+4
source share
2 answers

Try putting yourself in the position of the person reading this test after 6 months. Which test contains more information?

Given the set of two sentences, "Hello World" and "Goodbye World"

  • ... 4
  • ... flatten "Hello", "World", "Goodbye", "World"

, ? TDD, , .

+5

, , testCase, , , , ? , .

, . : " ?", - , , , , , , , ( , ).

+1

Source: https://habr.com/ru/post/1544718/


All Articles