软件工程第二次做业


1. 选择开发工具

  因为以前安装了Visual Studio 2017 ,这里只奉上截图了!
函数


2. 练习自动单元测试技术

编写test.h头文件

  编写test.h头文件,定义test类。代码以下:
'''C++
class test {//计算类
public:
bool isodd(int sum);
};
'''
工具

编写功能函数

  编写功能函数,实现判断一个数是否是奇数。代码以下:
'''C++
#include "pch.h"
#include"stdio.h"
#include
#include "test.h"
using namespace std;
单元测试

bool test::isodd(int num)
{
    return (num & 1) != 0;

    }

int main()
{
    return 0;
}

'''
学习

编写测试函数

  编写测试函数,测试1,0,-1的奇偶性。代码以下:
'''C++
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../ConsoleApplication1/test.h"开发工具

using namespace Microsoft::VisualStudio::CppUnitTestFramework;测试

namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:spa

TEST_METHOD(TestMethod1)
    {
        // TODO: 在此输入测试代码
        test a;
        Assert::AreEqual(true, a.isodd(1));
        Assert::AreEqual(false, a.isodd(0));
        Assert::AreEqual(true, a.isodd(-1));
    }

};

}
'''
code

测试结果

  本次测试主要测试了1,-1,0的奇偶性。三个测试用例都经过了。
blog


3.总结

  本次做业,学到了怎么用vsts进行单元测试,做业过程当中也遇到了许多的问题,例如本身建的头文件提示不是类名,.obj文件打不开等。也经过查阅资料解决了这些问题。   每一次做业都会有新的收获,我也会在学习的道路上一直走下去,屏幕前的你,也要加油啊!

相关文章
相关标签/搜索