lundi 27 juillet 2020

Test multiple methods doing the same thing(xUnit)

I'm new to xUnit, and I have some methods doing the same thing in different ways(all will return the same value for the same parameters).

Now I want to write a test for these methods. And I want to know if there's a way to write just one test method for them.

First: Can I pass methods to the test method(I set the method parameter to Func<> but cannot pass it through InlineData because it expects an object and Func isn't implicitly convertible(I don't know if there's a way))?

Second: Can I have multiple Asserts inside a test method and XUnit provide me a test for each Assert?

Third: Is there an Assert method to check if all my methods return the same value for the same parameters?

Fourth: Do you know another way?

It may be a little weird as each test checks one function usually I just want to know if it is possible

int method1(int x, int y) => x * y;
int method2(int x, int y) => (x==0 || y==0) ? 0 : x * y;

[Theory]
// [InlineData(method1)] method1 is not an object
void Test(Func<int,int , int> method){

// Multiple Asserts give me one test
}

Aucun commentaire:

Enregistrer un commentaire