Using DUnit from Delphi IDE and Avoiding Breakpoint on Exceptions

I use Delphi XE and I have a project group containing the main application and the DUnit test application. From time to time, I go to a DUnit test application to add some tests and run an existing one.

Some test code throws exceptions that are handled by the application but displayed by several Delphi Debugger debuggers, as I use to run the test application using the F9 shortcut, as I do with the standard application: this is not very convenient in this case.

I know about the SHIFT + CTRL + F9 shortcut to run without debugging and it is great when I remember to use it, but I often find that I press F9 , then grunt, then close the test application, and then press SHIFT + CTRL + F9 . What a waste of time.

So my question is: is there a better way? Can I define some parameters or use an expert to ensure that this particular application runs without debugging by default? Of course, I'm not the only one who has this problem.

Thanks in advance.

+8
debugging delphi dunit
source share
5 answers

No (at least not until D2009). Running without debugging is an IDE. A compiler flag would not help, as it is an IDE that hooks exe, and not vice versa. The only place where you could have this option would be in the project settings. But if this can make the IDE somewhat confusing, since the normal difference between Run and Run without debugging will be canceled. Then you need the third option: Run, Run with debugging, and Run without debugging, where a simple Run will be responsible for the project settings.

+5
source share

Add the start icon without debugging to the toolbar. Your problem is that you forgot the hotkey and click the icon. Therefore, delete another icon or move them around, for example: enter image description here

The more your application grows, the faster the slower the debugger starts. I run without debugging about 99% of the time, because the launch time of my application is from 2 seconds to 2 minutes, because it uses many runtime packages, and every BPL download in the debugger comes with a huge blow to my performance. So long, a slow, painful experience re-educated me to ask myself: "Do I need to debug?" If I do not, I will click on the green icon (in XE), which will replace the exclamation mark icon in older versions. (Smart UI Improvement, I think.). In previous versions of delphi, the green play button meant "work with debugging."

+2
source share

Disable "notify about language exceptions."

Disable notify on language exceptions

+2
source share

Good. You can use inextricable breakpoints [McKeeth] [Jensen] to ignore the exceptions that you force in your tests. The only way to save the breakpoints that I know of is to enable Tools> Options> Auto Save> Project Desktop.

0
source share

I understand your problem, but personally, I don’t think it is useful to be able to change the default behavior of F9 .

You have some test cases that are expected to throw exceptions. (NOTE: I actually think of tests that check for specific exceptions when bad inputs are given. No exception is "handled" by the application.) And I agree that in most cases you should not warn about this. However, an exception in other test cases would be a problem that I would like to get about as quickly as possible.

Therefore, my preferred mode of operation is usually notified of exceptions. And to have explicit code in some testing cases that explicitly disables exception notification only in the context of tests that will throw production code exceptions.

I have a technique that works very well for this.

In a test that was expecting to get exceptions, I write the following code:

begin TIDEDebugTools.DisableBreakOnExceptions; try //Test code ... finally TIDEDebugTools.EnableBreakOnExceptions; end; end; 

I think you need the source code for these two methods? :)

 unit IDEDebugTools; interface type TIDEDebugTools = class(TObject) public class procedure DisableBreakOnExceptions; class procedure EnableBreakOnExceptions; end; implementation { TIDEDebugTools } class procedure TIDEDebugTools.DisableBreakOnExceptions; begin end; class procedure TIDEDebugTools.EnableBreakOnExceptions; begin end; end. 

Where are the rest you ask?
There is no one - this!

... but there are a few instructions you need to follow:

  • Add a breakpoint for each of the methods.
  • Edit the breakpoint properties.
  • Select advanced options.
  • Turn off Break
  • And enable the options "Ignore subsequent exceptions" and "Process subsequent exceptions" for the corresponding corresponding method.

This is close to the jpfollenius idea for compiler directive parameters. It also addresses David 's issue of how you include these exceptions again. All you have to do is disable breakpoints to get all exceptions again.


Additional thoughts:

You mentioned:

Some test codes throw exceptions that are handled by the application.

If your application handles all of these exceptions, then:

  • Are your tests localized enough? If you test such large chunks of functionality, tests are more like system tests - and they are very difficult to maintain.
  • Do you use too many exceptions to handle business processes?
  • Is your application for a large number of non-local exclusions on swallowing?

Basically, it seems to me that your wording suggests "a bunch of exceptions that you don’t care too much about because they are" handled "." Many people make mistakes thinking that they handle exceptions when they simply swallow them and hide root problems.

0
source share

All Articles