软件测试实验四


 实验项目名称:实验四          

一、     实验目的

1、 掌握单元测试技术,并按单元测试的要求设计测试用例。 

2、 掌握一种单元测试工具的使用。

 

二、  实验内容

自行学习vs2010或vs2012或vs2015等单元测试工具的使用。

对下面被测代码进行测试且查看代码覆盖率,并录制操作视频,撰写实验报告。

 

三、  设计思路及结果

源程序

using System;

 

namespace BankAccountNS

{

    /// <summary>

    /// Cmp demo class.

    /// </summary>

    public class Cmp{

        public static int Largest(int[] list)

        {

            if(list.Length == 0)

                throw new ArgumentException("Empty list" );

            int index,max = Int32.MinValue ;

            for(index = 0; index < list.Length; index++)

            {

                if (list[index] > max)

                    max = list[index];

            }

            return max ;

        }

    }

}

 

测试程序

using Microsoft.VisualStudio.TestTools.UnitTesting;

using BankAccountNS;

 

namespace BankTests

{

    [TestClass]

    public class CmpTests

    {

        [TestMethod()]

        public void LargestTest()

        {

            int expect1 = 3;

            int[] numbers = new int[3] { 1, 2, 3 };

            int res = Cmp.Largest(numbers);

            Assert.AreEqual(res, expect1);

        }

        [TestMethod()]

        public void LargestTest2()

        {

            int expect1 = 4;

            int[] numbers = new int[3] { 1,2,3 };

            int res = Cmp.Largest(numbers);

             Assert.AreEqual(res, expect1);

        }

    }

}

 

 

运行截图

 

 

四、  个人体会

本次实验比较简单,因为之前学习过C#,对软件操作比较熟悉,跟着网上的资料做就可以做出来。

posted @ 2022-04-19 09:27  我试试这个昵称好使不  阅读(98)  评论(0编辑  收藏  举报