WaterBoy
WaterBoy

Reputation: 709

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?

Upvotes: 0

Views: 526

Answers (2)

Gawcio
Gawcio

Reputation: 1175

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

Upvotes: 1

Blundell
Blundell

Reputation: 76458

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

Upvotes: 0

Related Questions