I am trying to write unit tests in Unity that assert that logs, errors, and exceptions are raised as expected in my code, but I'm getting inconsistent results.
I'm using LogAssert.Expect(LogType, string) for each different kind of message. Logs and Errors work - if I expect a log/error with a particular message, then log/error with that same message, the test passes.
[UnityTest] //Passes
public IEnumerator LogMessage()
{
LogAssert.Expect(LogType.Log, "message");
Debug.Log("message");
yield return null;
}
[UnityTest] //Passes
public IEnumerator LogError()
{
LogAssert.Expect(LogType.Error, "error");
Debug.LogError("error");
yield return null;
}
But when I try expecting an exception, then LogException() with a new Exception() with a matching message, the test still fails:
[UnityTest] //Fails
public IEnumerator LogException()
{
LogAssert.Expect(LogType.Exception, "");
Debug.LogException(new Exception(""));
yield return null;
}
What do I need to change so that the exception is correctly matched as the one I was expecting, satisfying the test?