青岛早报电子版,何竝媚,刀片刺网
目录
我选择使用visual studio。
新工程work2
cpp中的代码如下
#include<iostream> #include"text.h" using namespace std; int text::add(int x, int y) { return x + y; } int text::sub(int x, int y) { return x - y; } int main() { return 0; }
头文件中的代码
#pragma once class text { public: int add(int x, int y); int sub(int x, int y); };
右键点击“解决方案”->"添加"->“新建项目”
紧接着在弹出的页面选择“本机单元测试项目
右键测试项目,然后选择属性
选择“链接器”->"输入"->"选择依赖项"
在编辑框中输入“..\work2\debug.*obj”
右键选中引用,点击“添加引用”
勾选需要引用的项目,也就是需要测试的项目
打开unittest1.cpp,编写代码如下:
#include "stdafx.h" #include "cppunittest.h" #include "../work2/text.h" using namespace microsoft::visualstudio::cppunittestframework; namespace unittest1 { test_class(unittest1) { public: test_method(testmethod1) { // todo: 在此输入测试代码 text a; int x = 8, y = 3; int z = a.add(x, y); int s = a.sub(x, y); assert::areequal(z, 11); assert::areequal(s, 5); } }; }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论