组件测试的测试框架

san*_*and 2 c++ testing cppunit scons python-unittest

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

  • SetUp(有一些输入文件需要读取或复制到某些特定的文件夹中.)
  • 执行(独立运行)
  • 撕下(清理以使系统处于旧状态)

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

我正在评估PyUnit,cppunit与scons为此.考虑运行这个问题以确保我的方向正确.你能建议任何其他测试框架工具吗?选择正确的测试框架应该考虑哪些其他要求?

Dmi*_*try 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.
}
Run Code Online (Sandbox Code Playgroud)

Scons可以在你.cc改变时建立你的建立,gTest可以用来setUp和tearDown你的测试.

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

一个不错的选择,国际海事组织,这是我们的一些测试自动化框架朝着移动,使用nosetests,再加上常见的程序库(如启动/停止服务,得到什么地位,能够在某些部件/禁用记录等) .这为您提供了一个易于使用的灵活系统.而且由于它使用python而不是C++或类似的东西,更多的人可能忙于创建测试用例,包括QE,它们不一定需要能够编写C++.