Some notes on xUnit usage

Hello everybody,

today I want to share with you small explanation about how xUnit works. 

Take a look at presented code:

[Theory]
[InlineData(3, 4, 5)]
[InlineData(7, 8, 9)]
public void MethodDemo(int numberOne, int numberTwo, int numberThree)
{
    double[][] data = new double[1][];
    data[0] = new double[3];
    data[0][0] = numberOne;
    data[0][1] = numberTwo;
    data[0][2] = numberThree;
 
    var sut = new Matrix(data);
}

If to describe this code in words, it has following meaning. 

  1. Attribute Theory says that it is test method which should be exeuted.
  2. Repeated twice Attribute InlineData says that method MethodDemo should be executed twice, with assigning to numberOne value 3 during first execution, value 7 during second execution. Number 4 to variable numberTwo in first execution, 8 to numberTwo variable during second execution and so on.

Take a look at picture that has visual representation:

I know that it is maybe not the best picture that you've seen in your life, but I hope it's self explanatory.

No Comments

Add a Comment