geberit / Revit.TestRunner

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

Opening a rvt file in OneTimeSetup #26

Closed sylvesp closed 2 years ago

sylvesp commented 2 years ago

Opening a Revit File during the [OneTimeSetUp] causes the test runner to NOT wait for the end of the test.

To reproduce: 1) Create a sample test that opens a Revit model:

public class SampleTest
{
    [OneTimeSetUp]
    public void OneTimeSetup(UIApplication uiApplication)
    {
    }

    [Test]
    public void SampleTest(UIApplication uiApplication)
    {
             uiApplication.OpenAndActivateDocument(@"c:\temp\hang1.rvt");
    }
}

Run "SampleTest" from the test runner => All Good

2) Move the revit model open into the OneTimeSetUp function:

public class SampleTest
{
    [OneTimeSetUp]
    public void OneTimeSetup(UIApplication uiApplication)
    {
            uiApplication.OpenAndActivateDocument(@"c:\temp\hang1.rvt");
    }

    [Test]
    public void SampleTest(UIApplication uiApplication)
    {
    }
}

Run "SampleTest" from the test runner => The test runner will display a dialog about the successful test completion WAY BEFORE the drawing finishes opening in Revit.

Please let me know if you have any questions.

sylvesp commented 2 years ago

Did some digging in the Test Runner code and I think that the problem is in ReflectionRunner.RunTestClassGroup()

internal async Task RunTestClassGroup( IGrouping<string, TestCaseDto> testClassGroup, bool isSingleTest, Action<TestCaseDto, bool> updateAction )
{
    if( !testClassGroup.Any() ) return;

    var instance = new TestInstance( testClassGroup.First().AssemblyPath, testClassGroup.Key );

    try {
   ==>      //Have to signal the Runner that the test is starting by calling:
   ==>   updateAction( .... something.... something);
   ==>      //Otherwise if the [OneTimeSetup] takes too long the runner won't wait
   ==>      //for it to finish and think that the test is over

        await instance.CreateTestInstance( mUiApplication );
    }
    catch( Exception e ) {
        foreach( TestCaseDto test in testClassGroup ) {
            test.Message = $"Exception in OneTimeSetup: {e.Message}";
            updateAction( test, true );
        }

        Log.Error( $"> {testClassGroup.Key} - {e.Message}", e );
    }
    ......
}
tobiasfloescher-geberit commented 2 years ago

Thanks for the issue and the solution. This looks in general as a good idea to notify when the test group is starting. Commit 2697f5c80df577f5ebc7df65fb03c17e09ae83d7