2

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

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

除此之外,我还希望有一些智能来确保 .cc 文件是否更改,所有可以验证更改的测试都应该运行。

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

4

2 回答 2

5

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

这是 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,在几乎所有其他情况下使用自定义的内部测试自动化框架。通常情况下,使用此类工具编写自己的工具可能比尝试调整和调整其他工具来满足您的要求更容易。

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

于 2010-01-17T09:31:54.380 回答
2

读完这篇文章http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle前段时间我去了 CxxTest。

设置好东西后(例如,您需要安装 python)编写测试非常容易(我对单元测试完全陌生)

我在工作中使用它,在我的解决方案中集成为一个视觉工作室项目。当测试失败时,它会产生一个可点击的输出,并且每次构建解决方案时都会构建并运行测试。

于 2010-01-17T16:34:31.303 回答