-7

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?

KutaBeach
  • 1,445
  • 21
  • 43

1 Answers1

0

Is it possible to track the number of exceptions being thrown by application?

When you catch them, count them.

Can I write a test that will print me such a number?

Once you have counted them print them. Print numbers in a unit test isn't very useful as they are usually ignored. It has to be automated.

Uncaught exceptions stops the execution, so its easy, but what about caught exceptions?

You are the one catching the exceptions so you have to check your code to record this. If it not your code, you don't need to worry about testing it.

How do I write a test that will tell me the number of activities completed in a second?

Perform a task repeatedly for a second and then print how many times it did it in a second. For long running tests it s can be better to run it for a few seconds and average it. Again, just printing this number is not always very useful.

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

Are we talking about in a unit test or some other means?

For a unit test, you can use byte code manipulation but this 100x times more complicated than changing the code.

You can use code coverage tools which give you this information and a report. e.g. Emma report or Idea's built in one. Note: this is not built in to the free version.

I want to see the value of expression during the execution of the code without changing the code

You can do this with beanshell for the expression and the debug interface. Again this 1000x more complicated than adding a line to the code.

Normally you would use a debugger for this.

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.

You can't stop on a condition without changing the code.

Most debuggers support this but they do so by performing a check after stopping the code and automatically continuing if the condition is not met.

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?

Use a Watch instead of Evaluate expression.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Thanks Peter! One note: I dont want to change the code not because I am lazy :) , but because I have problems with code I got from repository as dependencies, this code is not mine and its not 5 minute thing to replace that classes with my code with logging. Thats why I am always looking for methods that do not imply changing the code. – KutaBeach Sep 08 '12 at 19:22