File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes A set of questions on testing and debugging. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "A set of questions on testing and debugging." Watch "A set of questions on testing and debugging." New topic
Author

A set of questions on testing and debugging.

Dmitry Zhuravlev
Ranch Hand

Joined: Apr 14, 2010
Posts: 93
1) Is it possible to track the number of exceptions being thrown by application? Can I write a test that will print me such a number? Uncaught exceptions stops the execution, so its easy, but what about caught exceptions?

2) How do I write a test that will tell me the number of activities completed in a second? For example, average number exceptions thrown by code in a second, average number of entities saved per second, average number of users logged to the site per second etc. For example, I want to put some load on my webapp and find out how many entities it can save per second under such a load, where the limit etc

3) I want to know how many times some line is executed. Can I do it without changing the code?

4) I want to see the value of expression during the execution of the code without changing the code (*)

5) I want to stop the execution of my application not in the breakpoint, but only if some expression or variable is equal to some value (for example, stop app if this variable is null). Without changing the code, of course.

(*) probably I can use Watches for this. Idea debugger has this feature and I can see the value of some expression during the execution. But when the execution reaches that line second time an old value is cleared. How can I look at expression value in a dynamical way?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

1) Is it possible to track the number of exceptions being thrown by application? Can I write a test that will print me such a number? Uncaught exceptions stops the execution, so its easy, but what about caught exceptions?

AOP (aspect oriented programming) would be good for this. Take a look at AspectJ or the like.

2) How do I write a test that will tell me the number of activities completed in a second? For example, average number exceptions thrown by code in a second, average number of entities saved per second, average number of users logged to the site per second etc. For example, I want to put some load on my webapp and find out how many entities it can save per second under such a load, where the limit etc

A performance profiling tool would be better than a JUnit test. It will tell you were the most time in your code is spent so you know where to tune.

3) I want to know how many times some line is executed. Can I do it without changing the code?

Some performance tools will tell you this as well.

4) I want to see the value of expression during the execution of the code without changing the code (*)

I agree with the debugger. If you want a more permanent log, change the code. Or maybe use a debugging tool that tracks this info? I don't recall the name of it, but I remember reading about something that keeps track.

5) I want to stop the execution of my application not in the breakpoint, but only if some expression or variable is equal to some value (for example, stop app if this variable is null). Without changing the code, of course.

Watch expressions do this in your debugger.

It feels like there is a bigger question here. Like how to debug production code. Because that's the only reason I can think of why changing code would not be allowed.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dmitry Zhuravlev
Ranch Hand

Joined: Apr 14, 2010
Posts: 93
Jeanne Boyarsky wrote:It feels like there is a bigger question here. Like how to debug production code. Because that's the only reason I can think of why changing code would not be allowed.


Thank you Jeanne!

You are right.

The thing is that I need to debug the code which is not mine, I get it as a dependency from repository. If I want to change that code I'll have to code it, build it, and somehow give it to my program without installing into the main remote repository. Probably I can change maven POM and specify exact path to the dependency instead of repo group/artifact. Thats why I am looking for something more simple - i.e. using the debugging tools without changing the code.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

Got it. A debugger and profiler are definitely your best bets then. I'd start from "where is the time being spent" for performance rather than the # exceptions, executions of a line. You don't really care if my component sites around throwing exceptions all day if a sort operation takes 99% of the time in my component.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A set of questions on testing and debugging.