软件工程第二次作业-VSTS单元测试
一、选择开发工具
开发工具选择 Visual studio 2017 社区版,开发语言为C
由于之前已经安装完毕,所以不上传安装过程,主界面如下:
二、练习自动单元测试
使用的测试工具是VSTS,具体步骤如下:
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。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.编写测试程序,部分代码如下图
一共三个测试用例,包含正负数,测试结果如下
可见测试结果全部正确,测试完毕

更多精彩