Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unhandled log message Unity 5.6

Discussion in 'Editor & General Support' started by hectorSBM, Apr 7, 2017.

  1. hectorSBM

    hectorSBM

    Joined:
    Feb 4, 2017
    Posts:
    15
    Hello,

    I was using the old Unit Test tools from: https://bitbucket.org/Unity-Technologies/unitytesttools/

    There I created an unit test for my custom logger. The test simply writes a log/error/etc to the console and then listens to Application.logMessageReceived to make sure the log is correctly printed.

    When I upgraded to Unity 5.6.0f3, I get this error:
    TestError (0.024s)
    ---
    Unhandled log message: [Error] An error!
    ---
    Editors.Test.Logging.LoggerTest:TestError() (at Assets/Editor/Test/Logging/LoggerTest.cs:64)
    System.Reflection.MethodBase:Invoke(Object, Object[])
    NUnit.Framework.Internal.<>c__DisplayClass9_0:<InvokeMethod>b__0()
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
    ---
    An error!

    The test now fails, as before it was passing. Here is the code for the test:
    Code (CSharp):
    1. ...
    2.  
    3.             Application.logMessageReceived += OnLogReceived;
    4. ...
    5.  
    6.         [Test]
    7.         public void TestError()
    8.         {
    9.             string message = "An error!";
    10.  
    11.             _receivedLog = string.Empty;
    12.  
    13.             _logHandler.LogFormat(LogType.Error, null, message);
    14.             Assert.AreEqual(message, _receivedLog);
    15.         }
    16.  
     
    Last edited: Apr 29, 2017
    awsapps and einWikinger like this.
  2. hectorSBM

    hectorSBM

    Joined:
    Feb 4, 2017
    Posts:
    15
    Bump?
     
    einWikinger likes this.
  3. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    I'm getting those, too, now I upgraded from 5.5 to 5.6 - maybe there are new asserts or attributes to check for specific log messages to be generated?
     
  4. hectorSBM

    hectorSBM

    Joined:
    Feb 4, 2017
    Posts:
    15
    I think something changed in how Unit Test are handled, but I couldn't tell ya. I was hoping someone from Unity would respond. I've tried putting a try catch around the execution, and no excpection is thrown.
     
  5. WazzaM

    WazzaM

    Joined:
    Jan 10, 2015
    Posts:
    11
    @hectorSBM try changing [Test] to [TestCase] as there may be a different test runner involved.

    I noticed Unity has included the test tools directly in the editor since about version 5.5 with integrated test runners. I've made good use of these tools for a while now.

    You can also use Debug.Log to check the values and confirm that the test case is getting executed.
     
  6. hectorSBM

    hectorSBM

    Joined:
    Feb 4, 2017
    Posts:
    15
    No, the problem is when ILogHandler executes LogFormat for an error.

    This is from the console:
    TestError (0.023s)
    ---
    Unhandled log message: [Error] An error!
    ---
    Editors.Test.Logging.LoggerTest:TestError() (at Assets/Editor/Test/Logging/LoggerTest.cs:66)
    System.Reflection.MethodBase:Invoke(Object, Object[])
    NUnit.Framework.Internal.<>c__DisplayClass9_0:<InvokeMethod>b__0()
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
    ---
    An error!
     
    Last edited: Apr 29, 2017
  7. MatthewFSU

    MatthewFSU

    Joined:
    May 29, 2014
    Posts:
    2
    You can inform the test runner that you expect a message to occur with LogAssert.Expect.
     
    achimmihca likes this.
  8. hectorSBM

    hectorSBM

    Joined:
    Feb 4, 2017
    Posts:
    15
    @MatthewFSU No, there shouldn't be an exception when calling a log function.
     
    achimmihca likes this.
  9. youblistermypaint

    youblistermypaint

    Joined:
    Aug 5, 2015
    Posts:
    14
    Run into the same thing when upgrading my project from 5.3.6.

    I will confirm that it does in fact work if you add
    LogAssert.Expect
    as @MatthewFSU suggested.

    It's really odd that this behavior doesn't seem to be documented at all. Searching for the error string "Unhandled log message" brings you here. Maybe my Google Fu is just terrible. Does anyone have a link to some Unity documentation explaining this change in behavior?

    It also appears that you can use https://docs.unity3d.com/ScriptReference/TestTools.LogAssert-ignoreFailingMessages.html to disable this feature all together.
     
    seandanger and kiber_ like this.