我用googletest测试我的C++代码。当由于使用错误的索引访问std::vector而引发vector::_M_range_check异常时,googletest会报告:
C++ exception with description "vector::_M_range_check" thrown in the test body.
很好,现在我还想知道哪个向量,哪个索引和哪个范围。如何轻松获取此信息,并将测试代码保存在googletest单元测试用例中?
(我几乎要开始怀念Java了,因为它的很好……)
使用Visual Studio2010 C++和googletest。我是单元测试的新手,我已经创建了一个测试解决方案来试验它。我在解决方案中有三个项目:
HelloService (static lib)
HelloService.Tests (exe, a console app I think, linked with gmock_main.lib)
HelloApp (MFC exe, my main app)
我已经将googletest (和googlemock)编译、链接并成功运行。我的问题是代码测试开发周期。我正在尝试理解测试的正确工作流程。目前,如果我将HelloServic
我正在做一个Windows上的Visual Studio代码项目,我想使用Google Test。我只能包含头文件,当我尝试构建项目时,我得到了多个未定义的引用,可以在下面的错误列表中看到这些引用。 我已经在C:\googleTest中安装了Google Test。然后,我在文件夹中运行了以下命令: cmake .
cmake --build .
navigated to the googletest\googletest\gtest.sln
And build this with the help of Visual Studio i build the solutions by pre
我能够构建并使用它来运行单元测试。
在 my makefile for my unit_test.cpp中,我需要检查googletest库是否存在于..\googletest\中,并且只有当它们不存在时,我才想运行cmake和makeforgoogletest。
运行cmake和make,即使它们是构建的,也需要30秒,所以我只想运行cmake,如果必须的话,我只想运行cmake。
问题
在 my makefile for my unit_test.cpp中,我可以列出什么作为依赖项,以便只在实际需要时才生成googletest?
一种“蛮力”的方法是列出googletest\build
我的C++项目是用CMake构建的,包括使用GoogleTest的测试。为了避免不同项目与已安装/编译的GoogleTest版本之间的兼容性问题,我曾经决定将GoogleTest始终放在项目目录中。
我通过下载并构建GoogleTest作为我自己的测试项目(包括/链接gtest )的一部分来实现这一点。在相应的CMakeLists.txt中,如下所示
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
exe
我从centos7中获得了完全相同的结果,clang-3.6.1是使用fedora文件从源代码构建的。Ubuntu 14.04,clang-3.4
尽可能地使用来自wiki的说明,。这一页是6个月前更新的。
谷歌613仍在使用tr1
In file included from /home/hal/googletest/src/gtest-all.cc:39:
In file included from /home/hal/googletest/include/gtest/gtest.h:58:
In file included from /home/hal/googletest/include
我担心在单元测试中使用“不当”初始化的对象。假设我想测试一个函数:
void foo(SomeClass)
{
//do some stuff based on SomeClass.value
}
其中:
class SomeClass
{
OtherClass* ptr;
int uninterestingValue;
int value;
};
我想要做的是创建函数(仅在单元测试中可用,即在匿名命名空间中),其中:
SomeClass createDummy()
{
SomeClass dummy(nullptr, 0, //initialize uninteresting field
我有一个类是外部类的子类,我没有任何控制。外部类依赖于系统资源。例如
class MyClass : public ExternalBase // This class is from external framework and framework requires it to derive from this class.
{
int doSomePrivateThing(int );
public:
virtual int DoSomething(int );
virtual ~MyClass();
}
int MyClass::doSomePrivateT