利用VisualStudio白盒测试入门

来源:互联网 发布:广电网络箱有没有辐射 编辑:程序博客网 时间:2024/04/29 11:56
现在越来越多的软件开发使用白盒测试了,C++有CppUnit,.Net有NUnit, 在VisualStudio中也给我们提供了一套测试框架,但是该测试框架似乎只有在VS某几个版本才有。

    那么VisualStudio有哪些版本呢?以VisualStudio2005来看,他有些什么版本呢?各个版本有些什么区别呢?

    请参考网页:

    http://msdn.microsoft.com/en-us/vstudio/aa700921.aspx


    下表是从该网页中拷贝出来的。即Visual Studio 2005产品线一览图。

                    Visual Studio 2005 Product Line Overview

FeatureExpress ProductsVisual Studio Standard EditionVisual Studio Professional EditionVisual Studio Tools For OfficeVisual Studio Team System
IntelliSenseYesYesYesYesYes
Code editorYesYesYesYesYes
Code snippetsYesYesYesYesYes
Programming languages includedVB, VC#, VC++, and VJ# are single language. Visual Weincludes VC# and VBAllAllVB and VC# All
Office development support*NoNoNoSupport for Excel 2003, Word 2003, InfoPath 2003 2003 Support for Excel 2003, Word 2003, InfoPath 2003 2003
User experienceSimplified menu options and defaultsSimplified menu options and defaultsFullFullFull
Windows Forms designerVB, VC#, VC++, VJ# YesYesYesYes
Web Forms designerVisual Web DeveloperYesYesYesYes
Mobile Device Support*NoYesYesNoYes
Database design tools (create/modify tablesprocedures)LocalLocal and remoteLocal and remoteLocal and remoteLocal and remote
Data Access DesignersVB, VC#, VC++, VJ#:local, Visual Web Developer: localLocal and remoteLocal and remoteLocal and remoteLocal and remote
Documentation10mb "Getting Started"; Starter Kitfirst-time programmers; 200mb optional MSDN ExpressMSDNMSDNMSDNMSDN
Class Designer / Object Test Bench*NoYesYesYesYes
XML Editor SupportXML Only XML OnlyFull XML/XSLTFull XML/XSLTFull XML/XSLT
Deployment ToolsClickOnceYes YesYesYes
ExtensibilityUse 3rd party controls and content. No Macros,PackagesWrite, record, run macros, Write and consume Add-iPackages (partner products)Write, record, run macros, Write and consume Add-iPackages (partner products)Write, record, run macros, Write and consume Add-iPackages (partner products)Write, record, run macros, Write and consume Add-iPackages (partner products)
ReportingVisual Web Developer: SQL Server Reporting Services Add-in SQL Server Reporting Services SQL Server Reporting Services / Crystal Reports SQL Server Reporting Services SQL Server Reporting Services / Crystal Reports
Source Code ControlNoMSSCCI-compatible (Visual SourceSafe sold separately) MSSCCI-compatible (Visual SourceSafe sold separately) MSSCCI-compatible (Visual SourceSafe sold separately) MSSCCI-compatible (includes Visual SourceSafe, ViTeam Foundation Server sold separately)
DebuggingLocalLocalLocal / remote Local Local / remote
64-bit Compiler Support (Itanium)NoNoNoNoYes
64-bit Compiler Support (x64)NoYesYesNoYes
Server explorerNoNoAllAllAll
SQL Server 2005 IntegrationNoNoYesYesYes
Code ProfilingNoNoNoNoYes
Static AnalysisNoNoNoNoYes
Unit Testing*NoNoNoNoYes
Code CoverageNoNoNoNoYes
Project ManagementNoNoNoNoYes
Test Case ManagementNoNoNoNoYes
Offline Database ProjectNoNoNoNoYes
Data GenerationNoNoNoNoYes
Database RefactoringNoNoNoNoYes
Database Schema and Data CompareNoNoNoNoYes
Database Deployment ToolsNoNoNoNoYes
Size80mb (Express + SQL Express + .NET Framework Redist) Multiple CDs Multiple CDs Multiple CDs Multiple CDs
Additional Tools IncludedSQL Server 2005 Express EditionSQL Server 2005 Express EditionSQL Server 2005 Developer Edition SQL Server 2005 Developer Edition; Microsoft Office Developer Extensions; Access 2003 Runtime licenseSQL Server 2005 Developer Edition (included with clieonly)


  简单来说,我们可以归纳一下:
  Express---试用版
  Pro---全称是Visual Studio 2005 Professional Edition,是适合小规模使用的版本,授权8-10个人左右。
  Std---全称是Visual Studio Standard Edition,也是授权版本,比Pro多一些;
  VSTO---Visual Studio 2005 Tools for the Microsoft Office System,对office系列产品进行开发;
  VSTS---Visual Studio 2005 Team System,也是针对软件开发的各个层次最全面的一个版本
   可以看到,这几个版本中,只有VSTS有Unit Test的功能。所以要想利用VisualStudio来做白盒测试,必须安装VSTS,其他版本都没有。

    安装完VSTS后,开始写白盒测试代码吧。如图一步一步做吧:

    1.新建测试项目

    2.在生成的UnitTest1.cs文件中修改代码,如图所示:

    这样我们写了2个测试方法TestMethod1(),TestMethod2(); 分别让其通过和不通过。

    3.在实际的项目中,测试方法(Test Method)会非常多,为了方便管理,会建一些测试列表(Test List),如图所示:


    4.忘了说了,Test Manager这个工作区是怎么显示出来的了。

先在菜单 View – Toolbars - Test Tools 中选中,让其显示测试工具条,然后在测试工具条上点击Test Manager按钮,请看下图。


    然后呢,如上图所示,先在Test Manager中选中要运行的Test Method,然后点击用红框标出的按钮,就可以运行选中的Test Method了。
    运行完之后,打开Test Result面板,就能看到运行的结果了,可以看到,我们写的Test Method,一个Passed了,一个Failed了。
    呵呵,白盒测试入门就是这么简单。

    下一篇文章在本文基础上写,请看

    使用脚本运行VisualStudio测试代码



原创粉丝点击