体验Vs2005 beta2 测试工具

    在Vs2005中加入了单元测试工具,使用与NUnit差不多。但功能更加丰富了,而且使用更加方便,有利于项目的协调工作。而且还支持调试测试,(不知道NUnit支不支持,我是没用过。)方便我们调试出错代码。
    Vs2005 Test tool 与NUnit 特性类对应
            NUnit                                                Vs2005 Tools
     NUnit.Framework            Microsoft.VisualStudio.QualityTools.UnitTesting.Framework
     TestFixtureAttribute                   TestClassAttribute
    TestFixtureSetUpAttribute            ClassInitializeAttribute
    TestFixtureTearDownAttribute       ClassCleanupAttribute
    SetUpAttribute                                TestInitializeAttribute   
     TearDownAttribute                        TestCleanupAttribute
    
    创建一个测试工程。testproject.jpg
    打开UnitTest1.cs  它已经为我们生成了一个测试的Sample框架了.

None.gif [TestClass]
None.gif    
public   class  UnitTest1
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
public UnitTest1()
ExpandedSubBlockStart.gifContractedSubBlock.gif      
{
InBlock.gif            
//
InBlock.gif            
// TODO: Add constructor logic here
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Initialize() is called once during test execution before
InBlock.gif        
/// test methods in this test class are executed.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        [TestInitialize()]
InBlock.gif        
public void Initialize()
ExpandedSubBlockStart.gifContractedSubBlock.gif      
{
InBlock.gif            
//  TODO: Add test initialization code
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Cleanup() is called once during test execution after
InBlock.gif        
/// test methods in this class have executed unless the
InBlock.gif        
/// corresponding Initialize() call threw an exception.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        [TestCleanup()]
InBlock.gif        
public void Cleanup()
ExpandedSubBlockStart.gifContractedSubBlock.gif      
{
InBlock.gif            
//  TODO: Add test cleanup code
ExpandedSubBlockEnd.gif
        }

InBlock.gif
InBlock.gif        [TestMethod]
InBlock.gif        
public void TestMethod1()
ExpandedSubBlockStart.gifContractedSubBlock.gif      
{
InBlock.gif            Assert.IsTrue(
true,"this is work");
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

    熟悉NUnit的一眼就会明白那些Attribute是干嘛用的了。在里面写了一句简单的断言语句。这样就是一个简单的测试实例了。
    接下来运行这个测试实例。找到Test菜单项,testmenu.jpg选择"Manage and Execute Tests。在这管理器里面可以选择在项目中已经存在的测试实例。并选择是否运行测试。

testmanager.jpg 
    单击"By Test List"右边那上工具栏按钮。就开始执行测试了。查看测试结果
firstresults.jpg双击可以看到详细信息。
    刚才说到的还可以断点调试。很简单,只需要在测试实例设置断点,然后点击刚才的运行按扭的下拉框,可以看到有“Debug Checked tests”。这样就可以调试了。很方便!
debugTest.jpg
    就这么简单!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值