鸡蛋的故事- -| 回首页 | 2005年索引 | - -诗人的调查问卷 && 我爱夜

如何在Visual Studio2005下运行NUnit- -

                                      

决定用vs2005来做一个use case管理的小软件,熟悉一下工具,成果也可以算作是论文的一部分 :)

首先碰到的问题是我的NUnit2.2 在加载dll的时候提示如下错误:

System.BadImageFormatException:文件"MyTestLib"的格式无效

到网上查了一下,发现原来是NUnit加载.net runtime version的问题。在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下的一个单元测试工具(如果你竟然还没有听说过,那可就太...),这儿是官方网站,以及下载页面,推荐下载最新的2.2版本。

另外一些发现是以下的文章,原来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

- 作者: caff 访问统计: 2005年03月25日, 星期五 23:53 加入博采

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=1022366

回复

评论内容: