CSDN专家博客精华版

为人民服务!
  首页  :: 新随笔  :: 管理

Visual Studio2005下配置及运行NUnit

Posted on 2007-12-17 10:19  csdnexpert  阅读(86)  评论(0编辑  收藏  举报

  知道.net下有个NUnit,一直没有用它来写程序。今天测试了下试试,写点心得出来,一边写程序一边还得测试,浪费了很多时间精力。代码有了一定规模了,慢慢体会到单元测试的作用。用Nunit进行单元测试能及时发现新的Bug,保证原有的功能正常运行。而不必手工一个个的去试验,这是很宝贵的。在NUnit的安装目录的bin下面有两个config文件:nunit-gui.exe.config,nunit-console.exe.config,其中有一段startup的配置段,默认如下:
     <!--
     These statements specify the runtime versions supported
     in the order that they will be used if more than one
     is present. You can change the order of these if you like
     or remove any that do not apply.
 
  Since .NET 1.0 does not recognize the <supportedRuntime> elements,
  a <requiredRuntime> element is used in case it is the only version
  of the framework that is installed.
    -->
  <startup>
   <supportedRuntime version="v1.1.4322" />
   <supportedRuntime version="v2.0.40607" />
   <supportedRuntime version="v1.0.3705" />
   <requiredRuntime version="v1.0.3705" />
  </startup>

很明显,NUnit就是通过这儿配置来支持不同的.Net版本的(VS2005 Beat1的版本是"v2.0.40607")。这篇blog的建议是将其他无关的配置项删掉,it sure works,但是如果机器上同时安装了多个版本,就需要来回修改这个config文件——显然太麻烦。我是个懒人,有没有更省事的方法呢?试了几次,终于找到了,其实方法很简单:只需要把最新的版本的一行配置项放到最上面就可以了:
<startup>
   <!-- make it top here -->
   <supportedRuntime version="v2.0.40607" />
   <!-- leave others -->
   <supportedRuntime version="v1.1.4322" />
   <supportedRuntime version="v1.0.3705" />
   <requiredRuntime version="v1.0.3705" />
  </startup>

简单吧。测试了一下,机器上的另一个版本.net(v1.1.4322)也可以同时运行了,但是"v1.0.3705"没有测试,如果你是这一个版本,请告诉我你的测试结果 :)
注意的一点是根据你的工具不同(GUI或CONSOLE)配置不同的config文件.
ps:NUnit是.Net下的一个单元测试工具(如果你竟然还没有听说过,那可就太...),这儿是官方网站,以及下载页面,推荐下载最新的NUnit 2.4.3 (Recommended)2007-08-16版本。另外一些发现是以下的文章,原来vs2005中集成了unit test了,但是只在VSTS中发布,详情看这儿。
COOL stuff in VS2005 about test:
Testing in VS 2005

TDD and test generation in VS 2005 can be annoying and tricky if you don't watch out
 
 



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1835022