软件工程第二次作业


##**1. 选择开发工具**   **由于之前安装了Visual Studio 2017 ,这里只奉上截图了!** ![](https://img2018.cnblogs.com/blog/1644626/201904/1644626-20190412193458300-726479233.png)
##**2. 练习自动单元测试技术** ###**编写test.h头文件**   **编写test.h头文件,定义test类。代码如下:** '''C++ class test {//计算类 public: bool isodd(int sum); }; ''' ![](https://img2018.cnblogs.com/blog/1644626/201904/1644626-20190412193925974-1570260337.png)

编写功能函数

  编写功能函数,实现判断一个数是不是奇数。代码如下:
'''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:

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

};

}
'''

测试结果

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


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

posted on 2019-04-12 20:39  第五-fifth  阅读(161)  评论(2)    收藏  举报

导航