samedi 2 avril 2016

TestCase with lots of parameters

It's a mostly conceptual question. I have some class representing algorithm removing text from a (custom) TextArea control. I'd like to test it - the algorithm of course ;). I'm concerned with the lack of readability of my test method:

[TestCase(new[] { "some text asdf" }, 5, 0, 9, 0, "some  asdf", new int[0])]
[TestCase(new[] { "some text", "", "totally unimportant texttext that stays" }, 0, 0, 24, 2, "text that stays", new[] { 0, 1, 2 })]
public void ShouldRemoveSelectedText(string[] lines, int colStart, int lineStart, int colEnd, int lineEnd, string notRemovedText, int[] expectedRemovedLines) {
    var newLines = algorithm.RemoveLines(lines, new TextPositionsPair {
        StartPosition = new TextPosition(column: colStart, line: lineStart),
        EndPosition = new TextPosition(column: colEnd, line: lineEnd)
    });

    Assert.That(newLines.LinesToChange.First().Value, Is.EqualTo(notRemovedText));
    CollectionAssert.AreEqual(expectedRemovedLines, newLines.LinesToRemove.OrderBy(key => key));
}

As you can see it's a pretty simple test. I provide the algorithm with IEnumerable of string and selection area, however it's difficult to see - at first glance - which TestCase parameter goes where. I was wondering - is there a "cleaner" way of doing this? Sidenote: I have tests that are as simple as this one, but must be provided with even more parameters...

Aucun commentaire:

Enregistrer un commentaire