Custom attribute
Similar to the SqlServerData attribute available in the xUnit.net GitHub repository, you can create a custom attribute to load data from any source. A custom attribute class must implement DataAttribute, which is an abstract class that represents a data source to be used by a theory. The custom attribute class must override and implement the GetData method. This method returns IEnumerable<object[]>, which is used to wrap the content of the dataset to be returned.
Let's create a CsvData custom attribute that can be used to load data from a .csv file for use in data-driven unit tests. The class will have a constructor that takes two parameters. The first is a string argument containing the full path to the .csv file. The second ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access