0

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)

Zachary Moshansky
  • 1,673
  • 18
  • 32
  • Conditional breakpoints, sure. Scrapbook? Not sure... if you need an answer for breakpoint, I'll post one. But figured you already know about that one. – dispake Nov 20 '12 at 20:24
  • If I can use the conditional breakpoint to trigger something that will modify variables in the code while in debug mode it would work fine. Or anything to achieve the same effect. – Zachary Moshansky Nov 20 '12 at 21:38

2 Answers2

1

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)
dispake
  • 3,259
  • 2
  • 19
  • 22
  • Thanks for the answer :) Unfortunately this is the setup I currently have, I clarified the question to be specific that this part needs t o be automated. Due to the nature of the code it can be called quite a few times in rapid succession as I'm testing something with Lists and trying to prevent a bug that occurs with rapid scrolling. I would like to find an automated solution to kick off the scrapbook code but this answer would be great for others. – Zachary Moshansky Nov 21 '12 at 17:22
  • That's my next avenue to pursue. I've never used it so don't know much about it. Does it support variable modification on the fly? Our code is highly coupled to the framework and so I can't just use driver's to test individual functions. Thanks again for your input :) – Zachary Moshansky Nov 21 '12 at 18:24
  • 1
    You mentioned that it would be trivial to do in code so I imagine you could write an isolated test case that would simulate your scrolling List and then add your test code. It would be like running your app but only that piece of code - so yes, variables can be updated as it runs. – dispake Nov 21 '12 at 21:20
  • Thanks for the help and ideas dispake, due to androids framework (the way it compiles applications)and debugs them on devices, JUnit isn't really viable to test things that interact with the framework. By default the IDE with android SDK doesn't actually have the dependencies needed to run these methods that rely on the framework from JUnit. If we used more Dependancy injection, then it would be a viable option to inject all the android framework into the JUnit tests. Using Conditional Breakpoints also allows for debugging of the entire code on a device where weird bugs can occur. – Zachary Moshansky Nov 21 '12 at 23:32
0

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)
Zachary Moshansky
  • 1,673
  • 18
  • 32