Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback Don't abort tests due to a LogError

Discussion in 'Testing & Automation' started by Baste, Apr 29, 2020.

  1. Baste


    Jan 24, 2013
    I'm writing nice little unit tests like this:

    Code (csharp):
    1. var result = DoSomething();
    3. Assert.IsTrue(result, well_formed_error_message);
    But a Debug.LogError in DoSomething causes the entire test to abort and prints: "Unhandled log message: '[Error] blah blah blah'".

    Yeah, no. I want to run my test, please. That's why I wrote my test. I can turn it off on a case-by-case basis with LogAssert.ignoreFailingMessages = true, but I have to add that to every unit test as adding it to [SetUp] doesn't work.

    It drives me UP THE WALLS when a Unit testing framework suddenly has opinions about how our code should be written. Tests should only fail in three instances:
    - An assertion I wrote fails.
    - An exception is thrown during execution
    - No assertions are hit

    When I do a Debug.LogError instead of throwing an exception, it's because I want the program flow to continue. Don't turn error logs into exceptions behind my back.
    BAIZOR, g__b, gb_PRELOADED and 9 others like this.
  2. g__b


    Sep 17, 2014
    Had the same situation and agree completely with what you say.
    I just discovered that from Unity 2017 you can use:

    Code (CSharp):
    1. LogAssert.ignoreFailingMessages = true;
    Grabbed from: