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

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,349
    I'm writing nice little unit tests like this:

    Code (csharp):
    1. var result = DoSomething();
    2.  
    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

    g__b

    Joined:
    Sep 17, 2014
    Posts:
    39
    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: https://stackoverflow.com/a/46799168/1964407