关于使用TestDriven.Net 2.0的一点补充
                           关于使用TestDriven.Net 2.0的一点补充
电子科技大学软件学院03级02班 周银辉
2006.12的<程序员>杂志介绍了一个很好用的单元测试工具"TestDriven.Net 2.0", 对于新手(我也是)需要补充说明的几点是:
1, 要用"TestDriven.Net 2.0"进行单元测试除了安装"TestDriven.Net 2.0"外,你需要添加"nunit.framework"引用, 操作是"解决方案管理器-->引用-->(鼠标右键)添加引用-->.net-->nunit.framework.
2, 添加名字空间 using NUnit.Framework;
using NUnit.Framework;
为测试的类添加[TestFixture]特性
为测试方法添加[Test]特性
3, 示例代码
 using System;
using System;
 using System.Collections.Generic;
using System.Collections.Generic;
 using System.Text;
using System.Text;
 using NUnit.Framework;
using NUnit.Framework;

 namespace TestDrivenTest
namespace TestDrivenTest
 {
{
 [TestFixture]
    [TestFixture]
 public class TestClass
    public class TestClass
 {
    {
 [Test]
        [Test]
 public void TestRun()
        public void TestRun()
 {
        {
 Form1 frm1 = new Form1();
            Form1 frm1 = new Form1();
 int expected = 0;
            int expected = 0;
 int result = frm1.GetResult(2);
            int result = frm1.GetResult(2);
 Assert.AreEqual(expected, result);
            Assert.AreEqual(expected, result);
 }
        }
 }
    }
 }
}
 
电子科技大学软件学院03级02班 周银辉
2006.12的<程序员>杂志介绍了一个很好用的单元测试工具"TestDriven.Net 2.0", 对于新手(我也是)需要补充说明的几点是:
1, 要用"TestDriven.Net 2.0"进行单元测试除了安装"TestDriven.Net 2.0"外,你需要添加"nunit.framework"引用, 操作是"解决方案管理器-->引用-->(鼠标右键)添加引用-->.net-->nunit.framework.
2, 添加名字空间
 using NUnit.Framework;
using NUnit.Framework;为测试的类添加[TestFixture]特性
为测试方法添加[Test]特性
3, 示例代码
 using System;
using System; using System.Collections.Generic;
using System.Collections.Generic; using System.Text;
using System.Text; using NUnit.Framework;
using NUnit.Framework;
 namespace TestDrivenTest
namespace TestDrivenTest {
{ [TestFixture]
    [TestFixture] public class TestClass
    public class TestClass {
    { [Test]
        [Test] public void TestRun()
        public void TestRun() {
        { Form1 frm1 = new Form1();
            Form1 frm1 = new Form1(); int expected = 0;
            int expected = 0; int result = frm1.GetResult(2);
            int result = frm1.GetResult(2); Assert.AreEqual(expected, result);
            Assert.AreEqual(expected, result); }
        } }
    } }
}
 
                    
                

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号