有没有人知道如何使用Visual Studio 2010中的代码覆盖率结果在c ++中进行单元测试,我到处寻找一些答案.我想保持我正在测试的项目和测试项目分开.使用项目输出静态库不是解决方案,因为VS 2010中的代码覆盖工具无法将检测代码放在lib中.我已经尝试了dll作为要测试的项目,但是然后由于CLR创建了测试而无法正确链接:安全参数被打开以进行测试.人们有什么想法?或者MS只是无法制作c ++代码覆盖工具.
我对单元测试非常陌生,我有以下非常基本的程序:
#include "stdafx.h"
// classes example
#include <iostream>
using namespace std;
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
bool isEq ();
};
void CRectangle::set_values (int a, int b) {
x = a;
y = b;
}
bool CRectangle::isEq () {
if(x==y)
{
return true;
}
else
{
return false;
}
}
int main () {
CRectangle rect;
rect.set_values (3,3);
cout << "area: " << rect.area();
cout << " isEq: " << rect.isEq() …Run Code Online (Sandbox Code Playgroud)