If you write unit tests and use NUnit test framework this may be helpful. I decided to write this simple step by step project configuration because I tend to set it up on every new project but keep forgetting all its details of how to do this. Setting it up is simple and a one-time only process for each test project.

Getting NUnit

You can always get NUnit test framework directly from the web on http://www.nunit.org/ and install it on your machine but it may be better to use a more solution-specific approach by usingNuGet NUnit package that installs it only in a particular solution. Getting it using NuGet can either be done as outlined on the linked package page by using package manager console or using the package manager GUI by doing this:

  1. Right-click on project in Visual Studio Project Explorer; a popup context menu appears;
  2. Click on Manage NuGet Packages... menu option which will open package manager simple to use GUI;
  3. Wait for the dialog window to load packages from the web repo and then select NUnit;

This will automatically add NUnit library and tools to your solution folder and add relevant assembly references in your test project. Having a solution-specific NUnit version makes it future proof if newer NUnit versions are not backwards compatible. So one less thing to think about.

Executing unit tests

NUnit is a fine library, but it offers no Visual Studio integration per-se. It has an external program compiled either as a console app or a GUI. It runs your unit test assembly and executes any unit tests within.

Developers not having additional non-free Visual Studio tools usually run NUnit GUI tool and run those tests manually. But it's much easier if you can easily just hit F5 or Ctrl-F5 in Visual Studio that would compile unit tests and run the NUnit GUI tool automatically for you while also executing all unit tests on application start. The good thing is that you can also debug your unit tests this way in case you wanted to check something that seems to be invalid in your test code.

Project configuration

In order to automatically start NUnit test runner GUI tool you have to follow these steps to configure your test project to be capable of running/debugging unit tests:

  1. Open your test project properties by right-clicking on project in Visual Studio Project Explorer ans selecting option Properties...;
  2. Select Debug tab in project properties window;
  3. Set Start action as Start external program and point it to your local solution NUnit package installation; if you used NuGet package this is where you'll find your NUnit folder:your solution folder\packages\nunit2.5.10.11092\tools\nunit.exeOf course with the right NUnit version in folder name.
  4. Set Command line arguments to point to your test project assembly file like:YouTestProjectAssemblyName.dll /run
  5. Set Working directory to point to your test project's debug folder like:YourTestProjectFolder\bin\Debug
  6. Save project configuration properties and you're done;

I usually also configure my solution so that I set Startup project as Current selection. This makes it possible that hitting F5 runs my currently selected project. If I have a unit test file open it will run (start debugging) my unit test project, but if I'm currently working on ie. my web application file, it will automatically start debugging my web application. 

Debugging test assemblies compiled for .Net 4.0

If you're trying to debug your test assembly that is compiled for :net version 4.0 or later you may have problems hitting your breakpoints. Visual Studio simply says that no debug symbols have been loaded for your assembly. The problem is that NUnit is running under .Net 2.0, but your test assembly is compiled for .Net 4.0.

To still keep the capability of automatically running your tests by hitting F5 you will have to edit nunit.exe.config that's in the same folder as nunit.exe test runner GUI. All you have to do is to add these three lines directly under <configuration> configuration element:

toggle code line numbers...

   1:  <startup>
   2:      <supportedRuntime version="4.0" />
   3:  </startup>

This is all you need to know to configure your project to run NUnit unit tests directly from Visual Studio by starting NUnit test runner GUI. If you have any additional suggestions regarding this, please leave your comment below.

转:VS2010调试NUnit测试项目 (Running or debugging NUnit tests from Visual Studio without any extensions)的更多相关文章

  1. Unity3D-RPG项目实战(3):整合Visual Studio 2013开发环境

    古人云:工欲善其事必先利其器,IDE尽管属于一个非常上层的工具,可是一个好的IDE对工作效率提高还是非常大的. 事实上我还是满想用一下官方推荐的Mono,毕竟跨平台如今还是非常重要的一个特性.尝试了这 ...

  2. 右击存放项目的文件夹出现 open with Visual Studio Code 的打开方式

    最终效果 步骤1: 找到 Visual Studio Code 的安装位置 (右击桌面Visual Studio Code 图标-->属性-->打开文件夹所在位置) 新建一个可以编辑的 c ...

  3. Nunit测试工具使用实例

    前言: 本文主要是介绍了Nunit的基本使用,其中参详了很多已有的文章,由于最近要使用其进行测试,所以对网上的文章做了下整理,同时加入了一些自己的实践. NUnit的属性 TestFixture 它标 ...

  4. 远程调试 Asp.Net 项目

    项目部署到产品环境后,难免会发生一些故障,有一些可以在本地测试环境中直接重现,而有一些则无法重现.对于可以在本地测试环境中重现的Bug,开发人员往往能够很迅速地进行问题排查.而对于无法重现的Bug,就 ...

  5. Visual Studio 2017调试开源项目代码

    在我们的开发过程中很多时候我们会从GitHub上面下载一些开源的项目代码,然后在此基础上进行调试,正常情况下我们只需要将项目的源代码编译成Dll或者在.Net Core项目中直接引用相应的Nuget包 ...

  6. 使用 Visual Studio Team Test 进行单元测试和java中的测试

    C#中test测试地 方法一. 1.从NUnit官网(http://www.nunit.org/index.php)下载最新版本NUnit,当前版本为NUnit2.5.8. 2.安装后,在VS2008 ...

  7. 在Visual Studio上开发Node.js程序(2)——远程调试及发布到Azure

    [题外话] 上次介绍了VS上开发Node.js的插件Node.js Tools for Visual Studio(NTVS),其提供了非常方便的开发和调试功能,当然很多情况下由于平台限制等原因需要在 ...

  8. Visual Studio 2012使用NUnit单元测试实践01,安装NUnit并使用

    在Visual Studio 2012中,默认使用Microsoft自带的MS-Test测试框架.但,Visual Studio同样允许使用第三方测试框架,比如NUnit,xUnit,MbUnit,等 ...

  9. 剖析并利用Visual Studio Code在Mac上编译、调试c#程序

    0x00 前言 一周多以前的微软的Build大会上,微软发布了一个让很多人眼前一亮的工具,也是本文的主角——Visual Studio Code.很多使用Windows的朋友都很高兴,认为又多了一个很 ...

随机推荐

  1. oracle处理考勤时间,拆分考勤时间段的sql语句

    最近一直在用mysql数据库做云项目,有段时间没有接触oracle了,昨天有朋友叫我帮忙用oracle处理一个考勤记录的需求,我在考虑如何尽量精简实现上面花了一些时间.于是把这个实现做个总结. 需求如 ...

  2. 并查集+拓扑排序 赛码 1009 Exploration

    题目传送门 /* 题意:无向图和有向图的混合图判环: 官方题解:首先对于所有的无向边,我们使用并查集将两边的点并起来,若一条边未合并之前, 两端的点已经处于同一个集合了,那么说明必定存在可行的环(因为 ...

  3. ios 开发中出现的 pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug

    主要原因是某部分内存释放的太频繁,解决方法是检查函数的中[xxx release]; 将其注释掉 就行了

  4. WebRTC手记之框架与接口

    转载请注明出处:http://www.cnblogs.com/fangkm/p/4370492.html 上一篇文章简单地介绍了下WebRTC的协议流程,这一篇就开始介绍框架与接口. 一提到框架,本能 ...

  5. Java Web网站应用中的单点登录

    采用SSH架构加以说明:1.  建立一个登录管理类LoginManager2.  在LoginManager中定义一个集合,管理登录的用户.3.  在Spring中将LoginManager配置成单例 ...

  6. python3环境搭建(CentOS7.2)

    安装python3(自动安装pip3):yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqli ...

  7. lightning mdb 源代码分析(1)

    lighting mdb(lmdb) 是一个高性能mmap kv数据库,基本介绍和文档参见symas官网,本文将尝试分析其源代码结构以理解数据库设计的关键技术. 本系列文章将尝试从以下几个方面进行分析 ...

  8. Grunt - 前端开发所见即所得

    首先要安装全局的grunt-cli sudo npm install grunt-cli -g 1,项目中初始化npm文件,项目名不要和[关键词]如grunt重复,一直回车即可 npm init 2, ...

  9. lucene 3.0.2 搜索

    1.lucene 词频 转载:http://mxdxm.iteye.com/blog/989031 lucene in action作为action系列,确实坚持了其实用性的特色.全书花了很大的篇幅来 ...

  10. [转]把动态页面.aspx 生成静态页面.html

    本文转自:http://blog.csdn.net/csb5201314/article/details/5391688 如果要把主页Index.aspx 生成静态页面 Index.html后输出会提 ...