Dynamics NAV Integration

Tag: dynamics nav development

Logging Code Coverage to file in Dynamics NAV

by admin on nov.27, 2009, under Code

This entry will be about the CODECOVERAGE feature of Dynamics NAV.
This is done in version 5.0 SP1 but works in most newer versions.

I will not cover the normal use of Code Coverage. And by normal use I mean the scenario where you (the dynamics nav developer) manually start and stop the Code Coverage and view the code. I am sure most of you know how to handle that.

I recently found an new feature which I hadn’t really thought of before. And it became very useful indeed.

  1. The option to start Dynamics NAV with CODECOVERAGE enabled.
  2. The option to tell Dynamics NAV to log all CODECOVERAGE to a file.
  3. The option to start and stop the CODECOVERAGE from code.

In a problem solving situation where you cannot reproduce an error presented to you by a user, the combination of features 2 and 3 turned out to be a great tool.
Why?
Because it gives me the precise code that was executed at the time the error occured at the user’s computer, and I didn’t even have to be present.
He can send me the log file, and I can open it in my own Dynamics NAV client (which is also done using option 2 above).

Here is what you do:

1. Change the user’s shortcut, so that the client will always log CODECOVERAGE to file, when started. This is done by adding:

COVERAGEFILENAME=c:\somefilename.txt

…to your program shortcut.
Like this:

1-code-coverage-shourtcut

Now the client knows that whenever CODECOVERAGE is started – manually or by code – it must log to that file.

If you suspect something weird is going on in…say… the Sales Order Form, you can start Code Coverage in OnInit trigger:

CODECOVERAGELOG(TRUE);

..and stop it in the Onclose trigger:

CODECOVERAGELOG(FALSE);

Always running the form with Code Coverage enabled like this will of course have some impact on the performance for that user, but when hunting a problem it can be very useful.

1 Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!