我对我的课程ArithmeticSvc
和BigNumber
进行了测试。两个头文件都有各自的标题保护。当ArithmeticSvc
在其头文件中包含BigNumber
时,我对BigNumber.h
的测试会抛出重复的符号错误。相关文件如下:
#ifndef BIG_NUMBER_H
#define BIG_NUMBER_H
#include <string>
#include "stack.h"
using namespace std;
class BigNumber {
bool isNegative;
string num = "0";
public:
BigNumber(string num);
BigNumber(string num, bool isNeg);
string getNum();
};
#endif
ArithmeticSvc.h
#ifndef ARITHMETIC_SVC_H
#define ARITHMETIC_SVC_H
#include "bignumber.h"
#include <iostream>
#include <string>
using namespace std;
class ArithmeticSvc {
public:
ArithmeticSvc();
string evaluate(string exp);
};
#endif
bignumber_test.cc
#include "gtest/gtest.h"
#include "bignumber.h"
namespace {
TEST(BigNumber, ShouldPass) {
ASSERT_FALSE(false);
}
}
#endif
arithmeticsvc_test.cc
#include "gtest/gtest.h"
#include "arithmeticsvc.h"
namespace {
TEST(ArithmeticSvc, ShouldPass) {
ASSERT_TRUE(true);
}
}
duplicate symbol __ZN9BigNumber6isZeroEv in:
/var/folders/m2/cd4zt6556h992_b0g27h1s8c0000gn/T/arithmeticsvc_test-3a62e1.o
/var/folders/m2/cd4zt6556h992_b0g27h1s8c0000gn/T/bignumber_test-b9cad9.o
duplicate symbol __ZN9BigNumber6getNumEv in:
/var/folders/m2/cd4zt6556h992_b0g27h1s8c0000gn/T/arithmeticsvc_test-3a62e1.o
错误日志snippit:
g++ -std=c++11 -stdlib=libc++ -lgtest -lpthread *.cc -o main_test
我使用此命令编译测试:
{{1}}
有没有人知道如何测试具有依赖关系的类,这些依赖关系在Google测试中也有自己的测试?