是否有任何广泛使用的支持测试类别的 C++ 单元测试框架? [英] Is there any widely used C++ unit testing framework that supports test categories?

查看:24
本文介绍了是否有任何广泛使用的支持测试类别的 C++ 单元测试框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 CppUnit 进行测试,但对 类别.是否有任何广泛使用的 C++ 单元测试框架支持这种想法?

I'm currently using CppUnit for testing, but am frustrated by the lack of support for the concept of Categories. Is there any widely used C++ unit testing framework that supports this idea?

这是一个直接来自 NUnit 文档的示例:

Here's an example straight from NUnit documentation:

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  [Category("LongRunning")]
  public class LongRunningTests
  {
    // ...
  }
}

我们的想法是能够将测试分为不同的类别,并在指定的类别中执行测试,或者根据类别排除测试.

The idea is to be able to group tests in different categories, and to execute tests in specified categories, or perhaps to exclude tests based on their category.

我尝试过 CppUnit、Boost.Test 和 Google Test,但没有一个直接支持这个想法.

I have tried CppUnit, Boost.Test and Google Test, none of which directly support this idea.

例如,我有单元测试、集成测试、中等测试和大型 测试.unitintegration 测试运行得很快,所以我在自动构建的每个构建配置中运行它们:发布/调试、x86/x64、linux/windows.中等测试需要时间来运行,所以我只在Release|x64|windows构建中运行它们.大型测试作为开发辅助工具存在:它们永远不会在自动构建中运行.然后为了增加乐趣,我拥有仅存在于 x86|windows 中的功能(它很复杂).我用一个复杂的层次结构来做这一切,CppUnit 很高兴地支持它.但是,使用发布"、调试"、x86"等类别来执行此操作会更好.

For example, I have unit tests, integration tests, medium tests, and large tests. unit and integration tests run quickly, so I run them in every build configuration in the automated build: Release/Debug, x86/x64, linux/windows. medium tests take time to run, so I only run them in Release|x64|windows build. large tests exist as development aids: they are never run in the automated build. Then to add to the fun, I have features that only exist in x86|windows (it's complicated). I do all this with a complicated hierarchy, which CppUnit happily supports. However, it would be much nicer to do this with categories such as "release", "debug", "x86", etc.

在 CppUnit 中,我的测试目前在 Fixture 类中.理想情况下,我希望能够用类别标记这些灯具,然后我可以相应地对其进行过滤.

In CppUnit, my tests are currently in Fixture classes. Ideally, I'd like to be able to tag those Fixtures with Categories, which I could then filter accordingly.

测试层次结构不会做的一件关键事情是,类别做的是在一个夹具上有多个类别.

The one key thing that a test hierarchy doesn't do, which categories would do, is to have multiple categories on a single fixture.

推荐答案

--run_test Boost.Test 中的选项支持测试和/或套件名称的通配符匹配.我不完全确定匹配的灵活性,但是如果您要将类似标签的命名部分放入您的测试(-suite)名称中,您也许可以运行 --run_test=suite_LongRunning*/* 类似的东西.

我还偶然发现了 xUnit++属性可用于运行不同的类别.(因为它是仿照 NUnit 建模的,所以这也就不足为奇了.)

I also just stumbled on xUnit++ which has Attributes that can be used to run different categories. (Since it's modeled after NUnit, this should be no wonder.)

这篇关于是否有任何广泛使用的支持测试类别的 C++ 单元测试框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆