geberit / Revit.TestRunner

Unit Test Runner for Autodesk Revit
MIT License
81 stars 28 forks source link

Test with TestCase Attribute #1

Closed simonmoreau closed 4 years ago

simonmoreau commented 4 years ago

Hello,

I am trying to use Revit.TestRunner with NUnit TestCase attribute.

But although ordinary tests are working fine, I can't make the TestCase attribute working. After debugging these tests, I see that values in the TestCase attributes are not passed in the method and end up being null.

I looked into Revit.TestRunner code, it seems that the injection of the Application and UIApplication is removing any other parameters when invoking the method. I tried to correct that, but I don't really see where to start.

If you could point me in the right direction, I would be happy to work on a pull request!

Thanks for your work!

tobiasfloescher-geberit commented 4 years ago

Hello,

Thank you for trying out Revit.TestRunner.

At the moment, the TestCaseattribute is not supported. As you have probably seen, the Test method is called by reflection. This means, all the NUnit features must be implemented manually. To make the TestCaseattribute work, you must extend the possibleParamsarray in the ReflectionRunner.cs on basis of the MethodInfo.CusomAttributes. In addition, the invoke call must check its result if there is the ExpectedResultattribute set.

Hope that helps for the moment. I will take this feature in my backlog or wait for your pull request.

As workaround, I would suggest several test methods, which call a method where the test code lives.

[TestCase( 12, 3, ExpectedResult = 15)]
[TestCase( 15, 4, ExpectedResult = 19)]
public int SumTest( int n, int d )
{
    return n + d;
}
[Test]
public void SumTest1()
{
    Sum( 12, 3, 15 );
}

[Test]
public void SumTest2()
{
    Sum( 15, 4, 19 );
}

private void Sum( int n, int d, int expectedResult )
{
    Assert.AreEqual( n + d, expectedResult );
}
simonmoreau commented 4 years ago

Hello and thanks for your answer!

I have implemented your workaround for now, I will try to look into MethodInfo.CusomAttributes and see if I can propose you a pull request.

Thank you for your help,

Simon