Thursday 30 May 2013

Debugging and Testing in SharePoint 2010

Debugging and Testing in SharePoint 2010

Debugging and Testing in SharePoint 2010 If we are developing any applications in SharePoint the first point after the start of development that comes into mind is
How can we debugg or test the application
How can we get the detailed error
I am covering most of the avialable ways and tools to answer the debugging and testing questions.

Enable custom errors

The starting point for any developer is enable the cutom errors so that we can get detailed error instead of
routine error message ‘an unexpected error has occured’
Go to the location C:\inetpub\wwwroot\wss\VirtualDirectories\80 the default sharepoint site virtual directory.
Open the web.config file in any editor like notepad and search for the following xml

CallStack and PageLevelTrace

Change the CallStack and AllowPageLevelTrace attribute values to true
Before:
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
After:
<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="true">

CustomErrors node

Set the mode to off in CustomerErrors node
Before:
<customErrors mode="On" />
After:
<customErrors mode="Off" />

LAYOUTS folder CustomErrors node

Most of the time with the above changes we should see detailed error.
If not got to LAYOUTS folder at
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS
Modify the web.config file in it and set the mode to off in CustomeErrors node
Before:
<customErrors mode="On" />
After:
<customErrors mode="Off" />

Developer dashboard

SharePoint 2010 has powerfull tool called developer dashboard useful in debugging especially in a production environment.
With this tool we can see the stack trace of the current execution and also the SQL queries currently executing.
To enable the developer dashboard execute the following stsadm command:
stsadm -o setproperty -pn developer-dashboard -pv OnDemand
If we want to use powershell instead of stsadm, use the following script
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dashboardSetting = $contentService.DeveloperDashboardSettings
$dashboardSetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$dashboardSetting.Update()
Ok, some of us always like the superhero c#. For them use the following code
SPWebService cntService = SPWebService.ContentService;
cntService.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.On;
cntService.DeveloperDashboardSettings.Update();
After executing this command, refresh your site and you can see a new icon on the top after the username.
If we click it and we can see the developer dashboard at the bottom of the same page. We can view the stack trace and many more. Click the icon again to close
the detailed screen

Attach debugger

The most commong task done by any .net or sharepoint developer is attaching a debugger.
In the dev environment where code is avialable we can attach to w3wp.exe process of the valid application. Sometimes, if we are not sure, attach all the process.
Sometimes the breakpoints do not load even after attaching the debugger. To resolve this issue click the Select button in the ‘Attach to Process’ screen and select only the Managed (v2.0,v1.1,v1.0) option.
If we want to debugg a sandboxed solution in Visual Studio, we have to attach SPUCWorkerProcess.exe process

Watch the logs

Checking the SharePoint logs will give proper information on the error. But, most of the time we end up not observing that due to huge file.
We have one good tool ULSViewer to observe the logs. Download it from msdn http://code.msdn.microsoft.com/ULSViewer and observe the log file comforatably

Miscelaneous Tools for Testing and Debugging

SPDisposeCheck

Microsoft has good tool called SPDisposeCheck, which will scan the code and tell us where we are not releasing the memory because of not calling the Dispose() method.
This tool saves us a lot of time in tracking down memory leaks. We can download SPDisposeCheck from http://code.msdn.microsoft.com/SPDisposeCheck.


IE developer tool

Interner Explorer devloper tool that comes with IE is very good tool to track down client side issues. Just press f12 button after opening the site from IE.
It has some good feauteres inspite of displaying css tree, it shows the performance of the script code, including the number of times a function was used and the amount of time it took.


Firebug

This is addon tool for FireFox. It is same as IE developer tool


Visual Round Trip Analyzer

The Visual Round Trip Analyzer (VRTA) sits on top of the network monitor tool from Microsoft and is a free add-on.
It provides a graphic representation of how long it takes a client to talk to a server
We can download VRTA from www.microsoft.com/downloads/details.aspx?FamilyID=119f3477-dced-41e3-a0e7-d8b5cae893a3&displaylang=en


Fiddler

Fiddler(www.fiddlertool.com) is a web debugging proxy that logs all HTTP traffic between client and server.
Fiddler allows us to inspect all HTTP traffic, set breakpoints, and view our incoming and outgoing data


Visual Studio Testing tools

Not but the least, Visual Studio 2010 has got some awsome tools for unit testing, code coverage, impact analysis, coded UI testing, web performance testing, and load testing.
Ofcourse, how to use them is out of scope of this post. But, I will try in near future as they have really some cool features.


Conclusion

Hope this article provided some good information regarding debugging and testing the applications in SharePoint 2010. Let me

No comments:

Post a Comment