使CppUnit在netbeans 7.2上读取应用程序类
Getting CppUnit to read application class on netbeans 7.2
我正在同时学习c++和CppUnit,使用netbeans 7.2。
创建如下文件
#include <cstdlib>
using namespace std;
/*
*
*/
class Subtract{
public:
int minus(int a, int b){
return a-b;
}
};
int main(int argc, char** argv) {
return 0;
}
然后右键单击生成以下cppunit测试文件
#include "newtestclass.h"
CPPUNIT_TEST_SUITE_REGISTRATION(newtestclass);
newtestclass::newtestclass() {
}
newtestclass::~newtestclass() {
}
void newtestclass::setUp() {
}
void newtestclass::tearDown() {
}
int Subtract::minus(int a, int b);
void newtestclass::testMinus() {
int a=89;
int b=55;
Subtract subtract;
int result = subtract.minus(a, b);
CPPUNIT_ASSERT_EQUAL(34,result);
}
当我尝试运行测试时,它给出以下错误
g++ -c -g -I. -MMD -MP -MF build/Debug/GNU-MacOSX/tests/tests/newtestclass.o.d -o build/Debug/GNU-MacOSX/tests/tests/newtestclass.o tests/newtestclass.cpp
tests/newtestclass.cpp:25: error: 'Subtract' has not been declared
tests/newtestclass.cpp: In member function 'void newtestclass::testMinus()':
tests/newtestclass.cpp:30: error: 'Subtract' was not declared in this scope
tests/newtestclass.cpp:30: error: expected `;' before 'subtract'
tests/newtestclass.cpp:31: error: 'subtract' was not declared in this scope
make[1]: *** [build/Debug/GNU-MacOSX/tests/tests/newtestclass.o] Error 1
make: *** [.build-tests-impl] Error 2
如何使其正常工作?
在c++中,惯例是在头文件(.h文件)中声明类和函数,并在源文件(.cpp文件)中实现它们。
你的Subtract.h文件(declarations)应该只有这样:
class Subtract {
public:
int minus(int a, int b);
};
你的Subtract.cpp文件(实现)应该有这样的内容:
#include "Subtract.h"
int Subtract::minus(int a, int b)
{
return a-b;
}
然后在newtestclass.cpp文件中#include "Subtract.h"
相关文章:
- 从不属于应用程序的闪存读取
- 如何读取windows服务启动的控制台应用程序的输出
- 在应用程序启动时读取文件
- 如何通过C++库读取与安卓应用程序打包的文件?
- 从Qt应用程序读取元数据
- C#类过程 - 控制C 应用程序,不可能读取输出
- 如何使用Qt读取我的应用程序屏幕像素数据
- 如何在Ncurses应用程序中使用读取线
- 要读取一个从一个游戏应用程序(In C )到我的Android应用程序的文件
- 从 MAT 文件中读取 C 应用程序中的自定义类
- 在Qt控制台应用程序中读取和写入QProcess
- AccessViolationException从C++/CLI DLL读取C++应用程序中分配的内存
- 在Qt应用程序中读取python脚本C++输出
- 在C++中读取文件时应用程序冻结
- 从 mfc 应用程序点击网络服务,并希望从网络服务登录方法读取用户代码返回
- 桌面SCADA应用程序-通过C++读取和写入PLC
- 读取应用程序的输出
- 如何在vc++中执行从安装目录中读取数据的应用程序
- 序列化/封送C#中的简单对象以通过网络发送,供非托管C++应用程序读取
- 使CppUnit在netbeans 7.2上读取应用程序类