Search Unity

Question How to define an empty TestFixtureSource

Discussion in 'Testing & Automation' started by liortal, Apr 1, 2020.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I have a test fixture class that loads different prefabs and executes a series of tests on them.
    I am using the TestFixtureSource attribute to parameterize the fixture.


    In some cases, i need the TestFixtureSource property to return an empty enumeration (e.g: no tests should be executed).

    When building asset bundles, we launch tests from the command line, using a particular category ("Villages").
    The problem is that not all built asset bundles are actually associated to the given category, so my test fixture source "filters" them out, which will essentially return an empty enumeration.

    *Once we move to 2019.x, we could launch individual tests from editor code but for now we are still on Unity 2018.4, so i don't have access to the latest UTF package. we rely on the built-in Unity test runner.

    Example (simplified):
    Code (CSharp):
    1. [TestFixtureSource("VillagePrefabPaths")]
    2. [Category("Villages")]
    3. public class VillagePrefabTests
    4. {
    5.     public VillagePrefabTests(AssetPath villagePrefabPath)
    6.     {
    7.         this.villagePrefabPath = villagePrefabPath.path;
    8.     }
    9.  
    10.     private static IEnumerable<AssetPath> VillagePrefabPaths
    11.     {
    12.         get
    13.         {
    14.             List<AssetPath> assetPaths = new List<AssetPath>();
    15.  
    16.             return assetPaths.ToArray();
    17.         }
    18.     }
    19. }
    20.  
    This doesn't work, the test fixture fails to run with this error:
    OneTimeSetUp: No suitable constructor was found

    Is there any way to set this up ?
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,659
    I can't remember if it's in our version of NUnit or not, but try this: instead of producing an empty sequence, productivity a sequence containing one TestFixtureData member (which has null for the values) and call 'Ignore' on it before you return it.