Search code examples
javaandroidlogcatassertandroid-testing

The purpose of Assertation and Assert filter in LogCat how it can be useful and why it is different from Log.e()?


I'm curious I've never seen in my LogCat any messages marked as Assert. I have read documentation as here and here, but actually I didn't get the purpose of it and how it can be useful? I got that it throws errors, but why it is different with for example Log.e(). Can anyone tell me or point at some useful article about the purpose of it and give some small example? Thanks.


Solution

  • java.util.Log.ASSERT log level is something you see when you use the one of the wtf() logging methods.

    It generally means "assertion failure" i.e. a programming error with certain assumptions not being true and it's best to terminate the program immediately.

    junit.framework.Assert you linked to is another mechanism for expressing assertions. On failure, an AssertionFailedError will be thrown.