سؤال

Is it possible to link conditional breakpoints and scrapbook in Eclipse? I would like to have a conditional breakpoint trigger a piece of scrapbook code to be run (automatically). Something like...

if(x==4) //Conditional Breakpoint
->Run Scrapbook Code

I know this would be trivial by modifying the source but needs to be done against production code or during Codelock. Alternatively, is there any way of doing this using some other tools? *Note, this is for Android Development (Not sure if that'll affect solutions)

هل كانت مفيدة؟

المحلول

Only way I know of is a combination of a conditional break point and use of the display view.

First you would create your conditional break point by

  1. Right-clicking your break point
  2. Go to Breakpoint Properties
  3. Enable Condition
  4. Enter in your conditional

Then run your application and once your debugger hits your breakpoint

  1. Go to the Display view
  2. Enter in whatever piece of code you want to test
  3. Execute that statement(s)

نصائح أخرى

So I found it seems like it isn't possible to link a Conditional Breakpoint to Scrapbooks. Potentially one could hack the source to get the breakpoints to call scrapbook code or a custom variation of scrapbooks source; but, no implementation exists.

Luckily, I have found out that I didn't dig deep enough into the Conditional Breakpoint usage and found that they are rather powerful and I can resolve the problem without scrapbooks. (While researching it I read many tutorials and they all glossed over how to use them to their full extent and actually perform the variable modification in it's code statement.

if(position==0){
testObject=null;
com.example.test.customLogger(getClass().getSimpleName(),"Conditional BreakPoint Code");
}
return false;

A few things to note, hopefully they'll help someone else

  • While the above code will properly execute it's got a weird structure, in my opinion, as the "return false" statement is outside the code block that is only executed if the condition is met.

  • If you return "false" the debugger will not stop the thread, "true" and it will execute the code and stop.

  • You can use something like below and it will also trigger the breakpoint despite not being in an if statement. (Basically it accepts both Java and simple statements)

    "position==0"

  • It seems you cannot mix simple statements and java and throws very cryptic misleading messages when you do (Which lead me to believe I needed Scrapbooks in conjunction with conditional breakpoints
  • You must return a boolean at the end of your code block that the debugger uses to determine if it should pause the thread or continue on. Otherwise it will throw errors about not returning a boolean, which it does if you move the return inside the if block.

This approach works really well if your code is highly coupled to the class which in android consists of many methods and objects shared amongst them which makes unit testing tough to implement after the fact. However other avenues for testing that would be helpful are:

  • Android Developer's Monkey
  • Android Developer's MonkeyRunner
  • RoboGuice
  • Robotium
  • RobotElectric
  • JUnit (Not really viable as you can't test things interacting with android framework unless you use it in conjunction with RobotElectric)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top