Search code examples
androidassert

Can I use assert on Android devices?


I want to use the Assert keyword in my android apps to destroy my app in some cases on the emulator, or my device during testing. Is this possible?

It seems that the emulator just ignores my asserts.


Solution

  • The API provides the JUnit Assert.

    You can do

    import static junit.framework.Assert.*;
    

    now you can use all the functions like assertTrue, assertEquals, assertNull that are provided in the junit framework.

    Be careful not to import the Junit4 framework through eclipse, that would be the org.junit package. You have to use the junit.framework package to get it working on an android device or the emulator.