19

Recently we have been trying Unit Testing in a new project, now that we want to pass a Object to our test method with [InlineData], so we can utilize the same test method multiple times with multiple different data inputs.

[ClassData] and [MemberData] are also available, but do not seem to offer a solution, as to my understanding.

Basically, is there a way to pass Objects with XUnit, like so:

[Theory]
[InlineData(new Object { Attribute = 1 })]
public void Test(Object obj) 
{
    // Assert
    Xunit.Assert.NotNull(obj.Attribute);
}

Or is this not the correct convention or usage?

Passing int's and string's works fine using [InlineData]

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Sprite
  • 359
  • 1
  • 3
  • 11
  • 2
    and this article http://hamidmosalla.com/2017/02/25/xunit-theory-working-with-inlinedata-memberdata-classdata/ – Nkosi Jul 26 '18 at 13:31
  • A complete guide that sends complex objects as a parameter to Test methods [complex types in Unit test](https://stackoverflow.com/a/56413307/7487135) – Iman Bahrampour Jun 02 '19 at 08:46
  • 1
    Please refer this link https://stackoverflow.com/questions/22093843/pass-complex-parameters-to-theory – Vishwa G Mar 15 '21 at 12:17

0 Answers0