0

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?

Jave
  • 31,598
  • 14
  • 77
  • 90
WaterBoy
  • 697
  • 3
  • 13
  • 35
  • FYI I have added '-ea' to 'Default VM Arguments' in Window/preferences/java/editor/installed JREs' for the selected Installed JRE – WaterBoy Jun 26 '12 at 07:49
  • DalvikVM skips assertions by default, you can read more here: http://stackoverflow.com/questions/2364910/can-i-use-assert-on-android-devices – Jave Jun 26 '12 at 07:53

2 Answers2

1

Dalvik VM ignores Java assertions by default. To enable that, one must change debug.assert property, e.g 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
Gawcio
  • 1,125
  • 1
  • 9
  • 17
0

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

Blundell
  • 75,855
  • 30
  • 208
  • 233