Can I use LogAssert to check for errors in a unit test without cluttering the console?
Hi! I have a unit test that looks something like this:
public void OutOfBoundsTest()
{
// Setup code...
foreach (Vector2Int position in InvalidPositions)
{
this.Manager.Maze.CreateWall(position);
LogAssert.Expect(LogType.Error, new Regex("Error:.*"));
}
}
It is testing a function that will log an error to the console, but not throw an exception if something is wrong:
internal void CreateWall(Vector2Int gridPosition)
{
if (IsMazePositionValid(gridPosition.x, gridPosition.y))
this.cells[gridPosition.x, gridPosition.y].WallObject = WallFactory.GetWall();
else
Logging.LogError("Error: Attempted to create a wall at invalid position " + gridPosition);
}
Every time the test runs, the error is sent to the console. This is the only test out of my entire suite that is printing to the console when it is passing. (I use a lot of verbose assert checks in my tests to make failures easy to recognize and correct). Is there a way to disable the visible error, but still test for it? I tried adding Debug.unityLogger.logEnabled = false;
before the test, but it started failing, presumably because LogAssert will only see an error that was sent all the way to the console. I also don't want to use Debug.ClearDeveloperConsole();
if it will hide outputs from earlier tests that have run. Maybe I'm just misunderstanding/misusing LogAssert.