Corba
Corba

Reputation: 309

Unit testing with data from file

I'm trying to create a Lemmatizer. To test this lemmatizer I've obtained a csv with almost 75000 lemmatizations.

To test I've created a unit test that reads the file and checks if each line results in the correct lemma. The problem with this method is that it fails on the first error, which is of course as it should. But this doesn't give me an idea of the total progress of the lemmatizer. Is this the only one failing or is this just the first of thousands.

I could create a test that just counts the correct ones and checks if this number is equal to the number tested. But then I don't have a good clue about the failures.

The best thing that comes to my mind is to create a unit test per word + lemma. The downside of this is a) the work and b) makes it less easy to add a new word/lemma combo to test in respect to just adding it to the csv.

So my question is: Does anyone have a better option than the one above? Having a good track of "progress" but still see individual fails/success tests.

Upvotes: 1

Views: 159

Answers (1)

Bouke
Bouke

Reputation: 1577

For MSTest, this should help you out. Test execution will continue with the next row in your CSV file independant of the result of your assertions.

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "lemmatizations.csv", "lemmatizations#csv", DataAccessMethod.Sequential)]
[TestMethod]
public void LemmatizationTest()
{
    string lemma = TestContext.DataRow["lemma"]);
    string expected = TestContext.DataRow["expected"]);
    Assert.AreEqual(expected, lemma);
}

Upvotes: 2

Related Questions