MemberData attribute

The MemberData attribute is used when data theories are to be created and loaded with data rows coming from following data sources:

  • Static property
  • Static field
  • Static method

When using MemberData, the data source must return independent object sets that are compatible with IEnumerable<object[]>. This is because the return property is enumerated by the .ToList() method before the test method is executed.

The Test_CalculateLoan_ShouldReturnCorrectRate test method in the, The benefits of data-driven unit testing section, can be refactored to use the MemberData attribute to load the data for the test. A static IEnumerable method, GetLoanDTOs, is created to return a LoanDTO object using the yield statement to return the ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.