综合实践第五次个人作业——VSTS单元测试

作业要求:

在软件测试章节中中,我们介绍了不少VSTS的 软件测试工具,请使用一些其他平台上的测试工具,并写博客介绍如何在你的项目中具体使用。

一、选择开发工具

开发工具选择 Visual studio 2017 社区版,开发语言为C
由于之前已经安装完毕,所以不上传安装过程,主界面如下:

二、练习自动单元测试

使用的测试工具是VSTS,具体步骤如下:

1.编写一个判断三个数大小的程序

程序代码如下:

#include "pch.h"
#include <iostream>
#include "stdio.h"

int test(int a,int b,int c)
{
    int max;

    if (a > b)    max = a;
    else        max = b;
    if (c > max)  max = c;

    return max;
}
int main()
{
    int a, b, c,max;
    scanf_s("%d%d%d", &a, &b, &c);
    max = test(a, b, c);
    

    printf("max=%d", max);

    return 0;
}

头文件代码如下:

#pragma once
int test(int a, int b, int c)
{
    int max;

    if (a > b)    max = a;
    else        max = b;
    if (c > max)  max = c;

    return max;
}

2.创建测试程序,右键解决方案->添加->新建项目->测试

3.将测试项目test添加引用

4.右击UnitTest1->属性 -> 连接器 -> 输入 -> 附加依赖项,填写测试项目的obj文件路径

5.编写测试程序,部分代码如下图

一共三个测试用例,包含正负数,测试结果如下

可见测试结果全部正确,测试完毕

猜你喜欢

转载自www.cnblogs.com/zxj2019/p/10976830.html