Search Unity

Question NUnit automated tests: Need to ignore Log Errors

Discussion in 'Editor & General Support' started by zombience, Feb 7, 2023.

  1. zombience

    zombience

    Joined:
    Mar 29, 2012
    Posts:
    57
    Hi all,
    I've joined a team on a large complex project that has been in existence for nearly 5 years.
    So, before reading on, please understand at a project of this size and complexity, modifying the structure of the project or fixing the errors so they don't break my tests are not feasible short term solutions for my situation.

    My situation:
    Due to the project setup, I need to run tests in the main C# assembly. The majority of the project exists in main C# assembly, there is very little work isolated into .asmdefs. It is not a simple matter to convert the project to exist in an asmdef structure.

    This prevents me from using Unity's TestTools framework. I must rely on the pure NUnit tests (available in main C# assembly) if I want to have direct access to types, methods, etc, and those are things I need to inspect the state of objects, wait for the state of objects, etc.

    I'm encountering a situation where there are Debug.LogError messages showing up in the logs, and NUnit will automatically fail tests if errors are logged.
    I cannot silence these errors because they are coming from all over the project, including legacy packages from unity that we unfortunately rely on and cannot remove yet. In other words, to silence these debug logs I would need to essentially fix an incredibly wide range of issues all over the project, including replacing legacy packages we rely on. It isn't feasible in the short term.

    So, with all of that in mind, is there any way I can indicate to NUnit that it should not fail / stop tests when Debug.LogError messages are received?

    I have tried creating my own custom logger that reports nothing, or setting logEnabled to false, or both. Errors are still reported and fail the tests.
    I've also tried setting:
    Code (CSharp):
    1. TestContext.CurrentTestExecutionContext.StopOnError = false;
    Which does not work either.

    Thanks in advance


    I'm working in:
    Unity 2021.3.3f1
    Unity Test Framework v. 2.0.1-pre.18
    Unity's NUnit v.2.0.2 (package manager reports 2.0.2, but description says "custom version based on NUnit 3.5")
     
    Last edited: Feb 7, 2023
  2. zombience

    zombience

    Joined:
    Mar 29, 2012
    Posts:
    57
    additionally, I understand I could create my tests in an isolated asmdef to use Unity's TestTools framework, but then I cannot access any classes / methods / fields etc. on the objects I'm writing tests for.
     
  3. dan_ginovker

    dan_ginovker

    Joined:
    Jun 13, 2021
    Posts:
    76
    LogAssert.ignoreFailingMessages = true;