gpt4 book ai didi

c++ - 组件测试的测试框架

转载 作者:搜寻专家 更新时间:2023-10-31 00:05:34 25 4
gpt4 key购买 nike

我正在寻找适合我要求的测试框架。以下是我在自动化测试期间需要执行的步骤:

  • 设置(有一些输入文件,需要读取或复制到某些特定文件夹中。)
  • 执行(独立运行)
  • 拆除(清理以使系统恢复到旧状态)

除此之外,我还希望有一些智能来确保如果 .cc 文件发生更改,则应运行所有可以验证更改的测试。

我正在为此评估 PyUnit、cppunit 和 scons。考虑运行这个问题以确保我的方向正确。你能推荐任何其他测试框架工具吗?选择合适的测试框架还应该考虑哪些其他要求?

最佳答案

尝试 googletest又名 gTest它并不比任何其他单元测试框架差,但在易用性方面也可以击败一些。不完全是您正在寻找的集成测试工具,但在大多数情况下可以轻松应用。这wikipedia页面也可能对您有用。

这是 gTest 项目页面上的示例拷贝:

#include <gtest/gtest.h>

namespace {

// The fixture for testing class Foo.
class FooTest : public ::testing::Test {
protected:
// You can remove any or all of the following functions if its body
// is empty.

FooTest() {
// You can do set-up work for each test here.
}

virtual ~FooTest() {
// You can do clean-up work that doesn't throw exceptions here.
}

// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:

virtual void SetUp() {
// Code here will be called immediately after the constructor (right
// before each test).
}

virtual void TearDown() {
// Code here will be called immediately after each test (right
// before the destructor).
}

// Objects declared here can be used by all tests in the test case for Foo.
};

// Tests that Foo does Xyz.
TEST_F(FooTest, DoesXyz) {
// Exercises the Xyz feature of Foo.
}

Scons 可以在它们发生变化时负责构建您的 .cc,gTest 可用于设置和拆除您的测试。

我只能补充一点,我们在某些情况下使用 gTest,而在几乎所有其他情况下使用定制的内部测试自动化框架。通常情况下,使用此类工具编写自己的工具可能比尝试调整和微调其他工具来满足您的要求更容易。

在我看来,一个不错的选择是使用 nosetests,这是我们的测试自动化框架正在朝着的方向发展。 ,再加上一个通用例程库(如启动/停止服务、获取某物的状态、启用/禁用某些组件中的日志记录等)。这为您提供了一个灵活的系统,也相当容易使用。由于它使用 python 而不是 C++ 或类似的东西,更多的人可以忙于创建测试用例,包括 QE,这不一定需要能够编写 C++。

关于c++ - 组件测试的测试框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2080328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com