mercredi 2 mars 2016

How do I handle null/empty string/whitespace string in data-driven unit tests in Visual Studio, using CSV?

I want to do some data-driven testing in Visual Studio 2013, with the built-in testing framework. SQL is giving me endless headaches, XML looks messy, so that leaves CSV or Excel files.

I have some data-driven tests working with CSVs, but when I pull data from my CSV using TestContext.DataRow[n], it converts whitespace strings, empty strings, and the string literal "NULL" to DBNull. Even if I quote whitespace in my CSV, it still reads as DBNull.

At first, I was using the string literals "NULL" and "EMPTY" in my CSVs and converting them to null and String.Empty in my tests. However, I now want to do some testing with various combinations of whitespace strings, so creating keywords to replace is going to get a lot more tedious and probably error-prone.

Is this over-nullification the proper behavior? Is there a workaround?

Aucun commentaire:

Enregistrer un commentaire