Fido789
November 26, 2017, 1:54am
1
This test runs fine in edit mode:
public class LevelValidationTests
{
[UnityTest]
public IEnumerator LevelIsValid([ValueSource("LevelTestCases")] string levelName)
{
yield return null;
Assert.IsTrue(true);
}
public static IEnumerable<string> LevelTestCases
{
get
{
var themeManager = Resources.Load(ObjectNames.ThemeManager) as ThemeManager;
Debug.Assert(themeManager != null, "themeManager != null");
var levels = themeManager.Themes.SelectMany(t => t.Levels).Select(l => l.SceneName);
return levels;
}
}
}
In play mode at first I see all test cases, but when I try to run them I am getting
According to documentation I would say that ValueSource should be supported:
Or not?
Fido789
November 26, 2017, 2:41pm
2
Well it looks like the tests are actually done, it is just buggy how the results are displayed.
Before the tests are run (when I switch back and forth to EditMode tab):
After the tests are run:
EDIT: Maybe it is something with ScriptableObject loading from resource during play mode test, because if I hardcode level names everything is ok.
Fido789
November 26, 2017, 3:24pm
3
I solved it by moving resource loading to class variable like this:
static readonly IEnumerable<string> LevelNames = Resources.Load<ThemeManager>(ObjectNames.ThemeManager).Themes.SelectMany(t => t.Levels).Select(l => l.SceneName).ToList();
public static IEnumerable<string> LevelTestCases
{
get
{
return LevelNames;
}
}
Fido789
November 28, 2017, 3:09pm
4
Well, for the record, my problems had nothing to do with ValueSource attribute. Levels in my ThemeManager (ScriptableObject) was initialized inside Awake method. And it sometimes was called, sometimes wasn’t. I moved initialization to property getter and now everything works fine.
For the next time I should remember that Awake != constructor.