zoukankan      html  css  js  c++  java
  • Google Test Primer(四)——简单测试

    Simple Tests


    测试例子


    To create a test:

    创建一个测试


        1、Use the
    TEST() macro to define and name a test function, These are ordinary C++ functions that don't return a value.

             使用TEST()宏定义个和命名一个测试函数,这些函数是普通无返回值的C++函数。

        2、In this function, along with any valid C++ statements you want to include, use the various Google Test assertions to check values.
            
    这些函数中,可以使用任何合法的C++语句,可以使用各类Google Test断言检测值。

        3、The test's result is determined by the assertions; if any assertion in the test fails (either fatally or non-fatally), or if the test crashes, the entire test fails. Otherwise, it succeeds
         由断言决定测试结果,如果在测试中发生断言失败(无论致命的或非致命的),或者测试崩溃,整个测试失败,否则测试就是成功的。

    TEST(test_case_name, test_name) {

     ... test body ...

    }


    TEST()
    arguments go from general to specific. The first argument is the name of the test case, and the second argument is the test's name within the test case. Remember that a test case can contain any number of individual tests. A test's full name consists of its containing test case and its individual name. Tests from different test cases can have the same individual name.


    TEST()
    参数名从一般到特殊:第一个参数是测试案例名字,第二个参数是测试案例中的测试名字。记住,一个测试案例可以包含任何一个独立的测试。一个测试的全名由包含测试案例和独立测试名字组成。来自不同的测试案例的测试可以有相同的独立测试名字。


    For example, let's take a simple integer function:

    以简单的整数函数为例:

    int Factorial(int n); // Returns the factorial of n


    A test case for this function might look like:

    这个函数的测试一个测试案例可能如下:

    // Tests factorial of 0.

    TEST(FactorialTest, HandlesZeroInput) {

      EXPECT_EQ(1, Factorial(0));

    }

     

    // Tests factorial of positive numbers.

    TEST(FactorialTest, HandlesPositiveInput) {

      EXPECT_EQ(1, Factorial(1));

      EXPECT_EQ(2, Factorial(2));

      EXPECT_EQ(6, Factorial(3));

      EXPECT_EQ(40320, Factorial(8));

    }


    Google Test groups the test results by test cases, so logically-related tests should be in the same test case; in other words, the first argument to their
    TEST() should be the same. In the above example, we have two tests, HandlesZeroInput and HandlesPositiveInput, that belong to the same test case FactorialTest.


    Google Test
    组合了测试案例的测试结果,因此逻辑上相关的测试应该在同一个测试案例中。此外,相关测试的TEST()的第一个参数名应该相同,在上面的例子中,我们有两个测试HandlesZeroInputHandlesPositiveInput,但属于同一个测试案例FactorialTest


    Availability
    : Linux, Windows, Mac.

    转载请注明来自ubunoon[http://www.cnblogs.com/ubunoon]
  • 相关阅读:
    linux-网卡故障
    css hack
    IE7的overflow失效的解决方法
    Js中 关于top、clientTop、scrollTop、offsetTop的用法
    javascript作用域(Scope),简述上下文(context)和作用域的定义
    统计代码行数的小技巧
    sql复制表、拷贝表、临时表
    string.format
    手机号正则验证
    getBoundingClientRect() 来获取页面元素的位置
  • 原文地址:https://www.cnblogs.com/ubunoon/p/GoogleTestPrimerTestCase.html
Copyright © 2011-2022 走看看