Select to view content in your preferred language

NUnit and ArcGIS 10

324
1
09-14-2010 08:54 AM
LesleyBross
Deactivated User
I have been able to run some relatively simple unit tests (calling the VB .NET ArcObjects api with NUnit 2.5.7) and am sharing my findings since information on this topic is sparse.

In the TestFixtureSetUp() sub you need to use the AoInitialize Interface to initialize the test application with a suitable license. I think this requirement was added in 9.2.
Private m_ao As ESRI.ArcGIS.esriSystem.IAoInitialize
m_ao = New ESRI.ArcGIS.esriSystem.AoInitialize()
m_ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo)

Starting in ArcGIS 10, you also need to bind to a particular ArcGIS product before calling ArcObjects code. I included this call in TestFixtureSetUp() method as well.
Dim bound As Boolean = ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop)

If you need a handle to the IApplication interface, this article is helpful. It is called "How to automate ArcGIS desktop applications"

Be sure to shutdown the IAOInitialize interface and the IApplication interface (if it was created) in the TestFixtureTearDown() sub. Shutting down the IAOInitialize interface should be the last call to ArcObjects in an application.
If m_application IsNot Nothing Then
     Dim docDirtyFlag As IDocumentDirty2 = DirectCast(m_application.Document, IDocumentDirty2)
     docDirtyFlag.SetClean()
     m_application.Shutdown()
End If
m_ao.Shutdown()
0 Kudos
1 Reply
UjjwalNigam
Regular Contributor
Hi,
Does this apply to ArcGIS 10 only...? I mean can't we do it with previous ArcGIS versions....9.2 for example?

Regards
Ujjwal
0 Kudos