Hey everyone ๐
I'm currently contributing to an open source unity project. For a task i've picked up, i want to connect all available playable levels to the previous and next one, and test if it was done properly.
In essence there is a Scriptable object which serves as a container for all level packs, which in turn hold an array of levels, that are SO's themselves too.
Here is some of the relevant code:
public class AllLevelPacksSO : ScriptableObject
{
[field: SerializeField]
public LevelPackSO[] LevelPacks { get; set; } = default!;
private void OnEnable()
{
LinkAllLevel();
}
public void LinkAllLevel()
{
if (LevelPacks == null! || LevelPacks.Any(p => !p.Exists()))
{
Debug.LogError("Remove missing references in AllLevelPackSO to link level packs properly.");
return;
}
//...
}
//...
}
So there are a couple of tests i wrote so far, which all pass thanks to LogAssert.Expect().
However, my test setup looks like this:
public class LevelPackTests
{
private AllLevelPacksSO _sut = default!;
[OneTimeSetUp]
public void SetUp()
{
_sut = CreateSystemUnderTest();
}
private AllLevelPacksSO CreateSystemUnderTest()
{
LogAssert.Expect(LogType.Error, new Regex("Remove missing references.*?"));
var sut = ScriptableObject.CreateInstance<AllLevelPacksSO>();
//... OnEnable was called.
}
}
Of course the LogError will still appear, but this is confusing at best for anyone who will run the tests.
So is there anyway to not log that message when running it from tests? Or is this a fundamental error in my test/class design?