简体   繁体   中英

How to enable assertions in Eclipse v3.7.2

I can't seem to get assertions working in my eclipse android project. I have followed the directions at this site

But I still can't get them to work. My code looks like:

assert(false) : "PROGRAM ERROR - invalid dialog call";

any ideas?

Dalvik VM ignores Java assertions by default. To enable that, one must change debug.assert property, eg by invoking command in command line:

adb shell setprop debug.assert 1

Please note that you have to restart VM after that (force stop application: Settings->Apps->click on the app->Force stop).

Please also note that the setting is not persistent (assertions will be disabled again after phone reboot). However on rooted phones there's a way to make it persistent by putting /data/local.prop file containing line

debug.assert=1

What language are you expecting to use with the above?

I would try:

assertTrue("Expected true", true);

assertFalse("Expected false", true);

assertEquals("Expected equal", "same", "same");

Junit:

junit-docs/junit/framework/Assert.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM