Search Unity

Bug runSynchronous is broken (throws an exception)

Discussion in 'Testing & Automation' started by liortal, Apr 30, 2021.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I am creating code that should execute all edit mode tests as part of an editor build script.

    This is (roughly) the code i am using to execute tests:
    Code (CSharp):
    1. private static void RunEditModeTests()
    2. {
    3.     var testRunnerApi = ScriptableObject.CreateInstance<TestRunnerApi>();
    4.     testRunnerApi.RegisterCallbacks(new ClientBuildTestCallbacks());
    5.    
    6.     var filter = new Filter()
    7.     {
    8.         testMode = TestMode.EditMode
    9.     };
    10.  
    11.     var settings = new ExecutionSettings(filter);
    12.    
    13.     // This makes sure all tests are executed before proceeding with the next steps (e.g: building player)
    14.     settings.runSynchronously = true;
    15.  
    16.     testRunnerApi.Execute(settings);
    17.    
    18.     // TODO: generate XML report like we have now.
    19. }
    Executing this throws an exception (invalid cast), due to this code (AndFilter):
    Code (CSharp):
    1. public override bool IsExplicitMatch(ITest test)
    2. {
    3.   foreach (TestFilter filter in (IEnumerable<ITestFilter>) this.Filters)
    4.   {
    5.     if (!filter.IsExplicitMatch(test))
    6.       return false;
    7.   }
    8.   return true;
    9. }
    Specifically, the settings i have created seem to create a SynchronousFilter object, which does not derive from TestFilter, so this cast in the foreach loop is broken.

    Is this a known issue that should be fixed soon? or should i rely on something else rather than runSynchronously = true ?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562