您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > Nunit
使用NUnit对业务逻辑代码进行单元测试
作者:网络转载 发布时间:[ 2012/12/24 10:39:52 ] 推荐标签:

  步骤5:在Test_QX_Users项目录下新建一个批处理(这个位置可以不污染测试代码),命名nunit-test.bat,建议使用这种命名,可以知道使用哪个测试框架:


nunit-console Test_QX_UsersinDebugTest_QX_Users.dll


  步骤6:运行批处理nunit-test.bat,Nunit默认会在当前运行目录输出一个TestResult.xml测试报告,用在持续集成里再好不过了。


C:UsersappleDocumentsVisual Studio 2010ProjectsClassLibrary1ClassLibrary1
estsTest_QX_Users>nunit-test.bat

C:UsersappleDocumentsVisual Studio 2010ProjectsClassLibrary1ClassLibrary1
estsTest_QX_Users>nunit-console Test_QX_UsersinDebugTest_QX_Users.dll
NUnit-Console version 2.6.2.12296
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
  CLR Version: 2.0.50727.5466 ( Net 3.5 )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: net-3.5
.select name from users
infoworld
英雄
hero
finish Test

Tests run: 1, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.1430082 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
 


  TestResult.xml


<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
<test-results name="C:UsersappleDocumentsVisual Studio 2010ProjectsClassLibrary1ClassLibrary1 estsTest_QX_UsersTest_QX_UsersinDebugTest_QX_Users.dll" total="1" errors="0" failures="0" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2012-12-15" time="11:16:31">
  <environment nunit-version="2.6.2.12296" clr-version="2.0.50727.5466" os-version="Microsoft Windows NT 6.1.7601 Service Pack 1" platform="Win32NT" cwd="C:UsersappleDocumentsVisual Studio 2010ProjectsClassLibrary1ClassLibrary1 estsTest_QX_Users" machine-name="APPLE-PC" user="apple" user-domain="apple-PC" />
  <culture-info current-culture="zh-CN" current-uiculture="zh-CN" />
  <test-suite type="Assembly" name="C:UsersappleDocumentsVisual Studio 2010ProjectsClassLibrary1ClassLibrary1 estsTest_QX_UsersTest_QX_UsersinDebugTest_QX_Users.dll" executed="True" result="Success" success="True" time="0.143" asserts="0">
    <results>
      <test-suite type="Namespace" name="Test_QX_Users" executed="True" result="Success" success="True" time="0.132" asserts="0">
        <results>
          <test-suite type="TestFixture" name="TestQueryHelper" executed="True" result="Success" success="True" time="0.058" asserts="0">
            <results>
              <test-case name="Test_QX_Users.TestQueryHelper.TestQueryUsers" executed="True" result="Success" success="True" time="0.052" asserts="2" />
            </results>
          </test-suite>
        </results>
      </test-suite>
    </results>
  </test-suite>
</test-results>


  备注:项目完整代码可以从这里下载:

  http://download.csdn.net/detail/infoworld/4890295

  NUnit的vs插件:

  http://visualstudiogallery.msdn.microsoft.com/c8164c71-0836-4471-80ce-633383031099

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd