The Last Day Of Summer

.NET技术 C# ASP.net ActiveReport SICP 代码生成 报表应用 RDLC
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

第一次用NUnitAsp

Posted on 2004-07-16 17:38  Cure  阅读(2172)  评论(3编辑  收藏  举报

写的第一个NUnitAsp测试程序,是看着自带的帮助作的。

在WebForm上放一个TextBox和Button,测试类如下:
在项目中添加对NUnitAsp.dll的引用,再引用命名空间:
using NUnit.Framework;
using NUnit.Extensions.Asp;
using NUnit.Extensions.Asp.AspTester;

[TestFixture]
    
public class xxx :NUnit.Extensions.Asp.WebFormTestCase
    
{
        
const string myPage = @"http://localhost/WebApplication6/WebForm1.aspx";
        ButtonTester bt;
        TextBoxTester text;
        
protected override void SetUp()
        
{
            Browser.GetPage(myPage);
            bt 
= new ButtonTester("Button1",CurrentWebForm);
            text 
= new TextBoxTester("TextBox1",CurrentWebForm);
        }


        
protected override void TearDown()
        
{
        }

        
        [Test]
        
public void TestButton()
        
{
            NUnit.Extensions.Asp.WebAssertion.AssertVisibility(bt ,
true);
        }

        
public void TestText1()
        
{
            text.Text 
= "aaa";
            bt.Click();
            NUnit.Extensions.Asp.WebAssertion.AssertEquals(text.Text ,
"aaa");
        }

    }

打开NUnit运行测试,打开程序集,运行测试。看着绿色的进度条闪过,感觉真好
不过感觉要是界面上的东西多了,测试恐怕还是会有点麻烦。
刚开始学习,还请大家多多指教