Our project is using Unity 2018.4.0f1, so i don’t have access to UTF (the one that is packaged via UPM).
I want to set up a parameterized TestFixture but it does not work - the fixture never shows up in the test runner window.
My test class (fixture) should receive a string parameter (denoting a path to a prefab), load that prefab and execute different tests on it.
Here’s a (simplified) example of the code i’m trying to use. Nothing shows up in the test runner window:
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace Tests.ContentValidation
{
[TestFixture]
[TestFixtureSource(typeof(VillagePrefabProvider))]
public class VillagePrefabTests
{
private readonly GameObject villagePrefabPath;
public VillagePrefabTests(string villagePrefabPath)
{
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(villagePrefabPath);
this.villagePrefabPath = Object.Instantiate(prefab);
}
[Test]
public void TestSomething()
{
}
[Test]
public void TestAnotherThing()
{
}
}
public class VillagePrefabProvider : IEnumerable<string>
{
private const string PREFAB_ROOT = "Assets/Prefabs/Tests";
public IEnumerator<string> GetEnumerator()
{
var guids = AssetDatabase.FindAssets("t:prefab", new[] { PREFAB_ROOT });
foreach (var guid in guids)
{
yield return AssetDatabase.GUIDToAssetPath(guid);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}