在ArcGIS Engine和ArcGIS SDE开发中使用NUnit单元测试

来源:互联网 发布:淘宝中老年女装夏装 编辑:程序博客网 时间:2024/04/20 17:14

本文记录在在ArcGIS Engine和ArcGIS SDE开发中使用NUnit单元测试的步骤和方法:

 

步骤:

1新建项目,添加NUnit程序集的引用;

2.新建单元测试类SDEUnitTestClass,如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ESRI.ArcGIS.esriSystem;

namespace WinApp
{
    [TestFixture]
    class SDEUnitTestClass
    {
        [SetUp]
        public void Init()
        {
            LicenseInitializer m_AOLicenseInitializer = null;
            m_AOLicenseInitializer = new LicenseInitializer();
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB },
            new esriLicenseExtensionCode[] { });
        }


        [Test]
        public void TestGetGeoLayer()
        {
            string geoString = SDEClass.GetGeoLayer();
            Assert.That(geoString, Has.Length.GreaterThan(0));
        }
    }
}
注意:ArcGIS SDE是有授权的,即License,因此首先由初始化License的。

 

步骤3:生成DLL,

 

步骤4:启动NUnit GUI界面,执行测试,如下:

 

一片绿色,单元测试成功,

 

得到测试结果:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
<test-results name="G:/RIAWCFService/WinApp/WinApp/bin/Debug/WinApp.exe" total="1" errors="0" failures="0" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2011-01-26" time="11:56:10">
  <environment nunit-version="2.5.9.10348" clr-version="2.0.50727.4952" os-version="Microsoft Windows NT 6.1.7600.0" platform="Win32NT" cwd="C:/Program Files/NUnit 2.5.9/bin/net-2.0" machine-name="ZGC-20101217DYR" user="Administrator" user-domain="ZGC-20101217DYR" />
  <culture-info current-culture="zh-CN" current-uiculture="zh-CN" />
  <test-suite type="Assembly" name="G:/RIAWCFService/WinApp/WinApp/bin/Debug/WinApp.exe" executed="True" result="Success" success="True" time="45.349" asserts="0">
    <results>
      <test-suite type="Namespace" name="WinApp" executed="True" result="Success" success="True" time="45.341" asserts="0">
        <results>
          <test-suite type="TestFixture" name="SDEUnitTestClass" executed="True" result="Success" success="True" time="45.334" asserts="0">
            <results>
              <test-case name="WinApp.SDEUnitTestClass.TestGetGeoLayer" executed="True" result="Success" success="True" time="45.327" asserts="1" />
            </results>
          </test-suite>
        </results>
      </test-suite>
    </results>
  </test-suite>
</test-results>

 

可以看到,该方法是从SDE中获取图层信息的方法,耗时45.327秒。

 

 

 

原创粉丝点击