NUnit的使用(2)——实际测试过程中,程序代码和测试代码是分开的

 在大型项目开发过程中,软件开发和测试是同步进行的。程序代码由软件开发人员编写,而测试代码由测试工程师编写,因此这两种代码应该分别保存在不同的类文件中,以便统一管理,下面举一例。

1、创建C#类库,名为CompareMaxNumber。

2、创建C#类文件,名为LargestNumber.cs。此代码由软件开发人员编写,用于判定list列表中的最大值。

 

using System;
using System.Collections.Generic;
using System.Text;

namespace CompareMaxNumber
{
    public class LargestNumber
    {
        public static int MaxNumber(int[] list)
        {
            int max = Int32.MinValue;
            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] > max)
                {
                    max = list[i];
                }
            }
            return max;
        }
    }
}

 

3、创建C#类文件,名为TestLargestNumber.cs。此代码由软件测试人员编写,用于测试LargestNumber.cs中的逻辑。

 

using System;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;

namespace CompareMaxNumber
{ 
    [TestFixture]
    class TestLargestNumber
    {
        [Test]
        public void TestLargest()
        {
            Assert.AreEqual(9,LargestNumber.MaxNumber(new int[] {8, 7, 9}));
        }

    }
}

 

4、设置类库的启动操作,将启动外程序的路径设置为nunit.,exe。启动调试,点击run,得到运行结果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值