Pair Testing

All-Pairs Testing is a test design method to deal with the combinatorics problem of defining test cases in a systematic way.

成对组合覆盖这一概念是Mandl于1985年在测试Aad编译程序时提出来的。Cohen等人应用成对组合覆盖测试技术对Unix中的“Sort”命令进行了测试。测试结果表明覆盖率高达90%以上。可见成对组合覆盖是一种非常有效的测试用例设计方法成对组合覆盖要求任意两个因素(输入条件)的所有水平组合至少要被覆盖1次。组合覆盖的算法已经被很多工具实现,测试人员可以直接利用这些工具,例如:TConfig、微软的PICT等。下面介绍一下使用PICT设计测试用例的过程。 

PICT,全称是Pairwise Independent Combinatorial Testing tool,是微软公司内部使用的一款成对组合的命令行生成工具,现在已经对外提供,可以从

官网:http://www.pairwise.org/ 常用的Pairwise工具集:http://www.pairwise.org/tools.asp上下载到。

PICT工具原理和算法实现可以参考http://msdn.microsoft.com/en-us/library/cc150619.aspx

 

model.txt
 
  • The model defines the parameters that need to be 'combined' and their values.
  • Parameter names and values are defined by "parmname: val1, val2, ..." (list of comma seprated values).
  • Values can be any string (numbers, names, logical names like "empty")
  • You can define constraints to make sure the tool does not generate test case variants that are illegal.
  • For details see  PICT language reference
    #
    # PICT Example model: Parameters to the windows 'FORMAT' command
    #
     
    Type: Primary, Logical, Single, Span, Stripe, Mirror, RAID- 5
    Size: 10 , 100 , 500 , 1000 , 5000 , 10000 , 40000
    Format method: quick, slow
    File system: FAT, FAT32, NTFS
    Cluster size: 512 , 1024 , 2048 , 4096 , 8192 , 16384 , 32768 , 65536
    Compression: on, off
     
    # some simple constraints
    IF [File system] = "FAT" THEN [Size] <= 4096 ;
    IF [File system] = "FAT32" THEN [Size] <= 32000 ;
     
     
     

    The number of test cases produced by different tools for the same model:

    ModelAETG 1)IPO 2)TConfig 3)CTS 4)Jenny 5)TestCover 6)DDA 7)AllPairs [McDowell] 5)PICTEXACT8)IPO-s 9)ecFeed 10)
    349999119?999910
    313151715151815181718151719
    415 317 229413440393829353437?3237
    41 339 235282630292821272627212328
    2100101514101610151415101016
    1020180212231210193181201197210?220203
     
     

转载于:https://www.cnblogs.com/ellie-test/p/6806853.html

### C++ 中 `testing::Test` 的作用及用法 #### 1. `testing::Test` 的定义与作用 `testing::Test` 是 Google Test 框架中的一个基类,用于为单元测试提供基本的功能支持。所有自定义的测试夹具(fixture)类都必须继承自 `testing::Test`。通过继承 `testing::Test`,可以实现测试前的初始化(`SetUp`)和测试后的清理(`TearDown`)功能[^3]。 #### 2. 基本结构 在 Google Test 中,测试通常分为以下部分: - **测试夹具类**:继承自 `testing::Test`,用于共享多个测试用例之间的资源。 - **`SetUp` 方法**:在每个测试用例执行之前调用,用于初始化测试环境。 - **`TearDown` 方法**:在每个测试用例执行之后调用,用于清理测试环境。 #### 3. 示例代码 以下是一个使用 `testing::Test` 的完整示例: ```cpp #include "gtest/gtest.h" // 定义一个需要测试的类 class Calculator { public: int Add(int a, int b) { return a + b; } }; // 定义测试夹具类 class CalculatorTest : public testing::Test { protected: Calculator calc; // 在每个测试用例之前调用 void SetUp() override { // 可以在这里初始化资源 } // 在每个测试用例之后调用 void TearDown() override { // 可以在这里清理资源 } }; // 编写测试用例 TEST_F(CalculatorTest, AddTwoPositiveNumbers) { EXPECT_EQ(calc.Add(1, 2), 3); } TEST_F(CalculatorTest, AddNegativeAndPositiveNumber) { EXPECT_EQ(calc.Add(-1, 1), 0); } ``` #### 4. `testing::Test` 的主要方法 - **`SetUp`**:这是一个虚函数,用户可以在派生类中重写它,用于在每个测试用例执行之前进行初始化操作。 - **`TearDown`**:这也是一个虚函数,用户可以在派生类中重写它,用于在每个测试用例执行之后进行清理操作。 #### 5. 测试夹具的作用 测试夹具的主要作用是减少重复代码并确保测试环境的一致性。例如,在上述示例中,`Calculator` 对象被创建一次并在所有测试用例中共享,避免了在每个测试用例中重复创建对象的麻烦。 #### 6. 参数化测试 除了普通的测试用例,Google Test 还支持参数化测试。在这种情况下,测试夹具类需要继承自 `testing::TestWithParam<T>`,其中 `T` 是参数类型。参数化测试允许用户为同一个测试逻辑提供不同的输入数据[^2]。 以下是一个参数化测试的示例: ```cpp #include "gtest/gtest.h" class ParamTest : public ::testing::TestWithParam<std::pair<int, int>> {}; TEST_P(ParamTest, AddTest) { auto param = GetParam(); int a = param.first; int b = param.second; EXPECT_EQ(a + b, a + b); // 简单验证加法 } INSTANTIATE_TEST_CASE_P(AdditionTests, ParamTest, ::testing::Values(std::make_pair(1, 2), std::make_pair(3, 4))); ``` #### 7. 配置与运行 在主函数中,可以通过调用 `testing::InitGoogleTest` 来初始化 Google Test,并通过 `RUN_ALL_TESTS()` 执行所有测试用例。此外,还可以通过设置全局标志来控制测试输出格式、颜色等[^5]。 ```cpp int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); testing::FLAGS_gtest_output = "xml:report.xml"; // 输出 XML 报告 testing::FLAGS_gtest_color = "yes"; // 启用彩色输出 return RUN_ALL_TESTS(); } ``` ### 注意事项 - 如果在使用 Google Test 时遇到链接错误(如 `undefined reference to 'typeinfo for testing::Test'`),可能是由于未正确链接 gtest 库。确保在编译时将 gtest 和 gtest_main 库链接到项目中[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值