GoogleTestPrimer
Getting started with Google C++ Testing Framework
开始Google C++测试框架
Google C++ Testing Framework Primer
Google C++测试框架入门
Introduction: Why Google C++ Testing Framework?
介绍:为什么是Google C++测试框架
Google C++ Testing Framework helps you write better C++ tests.
Google C++测试框架帮助你编写更好的C++测试。
No matter whether you work on Linux, Windows, or a Mac, if you write C++ code, Google Test can help you.
无论你是在Linux,windows还是Mac上编写C++代码,Google Test都可以帮助你。
So what makes a good test, and how does Google C++ Testing Framework fit in? We believe:
因此,怎样才能作为一个好的测试,Google C++ 测试框架如何满足呢?我们相信:
- Tests should be independent and repeatable. It's a pain to debug a test that succeeds or fails as a result of other tests. Google C++ Testing Framework isolates the tests by running each of them on a different object. When a test fails, Google C++ Testing Framework allows you to run it in isolation for quick debugging. Tests应该是独立的和可复现的,以其他测试成功或失败的结果来debug测试是痛苦的。Google C++测试框架通过在不同的对象上运行每个测试将测试隔离起来。当一个测试失败时,Google C++ 测试框架允许你在快速debugging时继续运行隔离测试。
- Tests should be well organized and reflect the structure of the tested code. Google C++ Testing Framework groups related tests into test cases that can share data and subroutines. This common pattern is easy to recognize and makes tests easy to maintain. Such consistency is especially helpful when people switch projects and start to work on a new code base. Tests应该被很好的组织,应该反射测试代码的结构。Google C++测试框架组合相关测试为能够共享数据与子过程的测试案例,当人们改变工程,开始在新的代码基础上工作时,这种一致性特别有用。
- Tests should be portable and reusable. The open-source community has a lot of code that is platform-neutral, its tests should also be platform-neutral. Google C++ Testing Framework works on different OSes, with different compilers (gcc, MSVC, and others), with or without exceptions, so Google C++ Testing Framework tests can easily work with a variety of configurations. (Note that the current release only contains build scripts for Linux - we are actively working on scripts for other platforms.) 测试应该是可移植的和可重用的。开源社区拥大量中性平台下的代码,相关测试也需要中性平台下的测试。Google C++测试框架可在不同系统上使用或不使用异常的不同编译器(gcc, MSVC和其他编译器)上运行,因此Google C++测试框架在各种配置下可以很容易运行(注意当前发布平台仅包含Linux下的构建脚本——我们正积极编写在其他平台上的构建脚本)。
- When tests fail, they should provide as much information about the problem as possible. Google C++ Testing Framework doesn't stop at the first test failure. Instead, it only stops the current test and continues with the next. You can also set up tests that report non-fatal failures after which the current test continues. Thus, you can detect and fix multiple bugs in a single run-edit-compile cycle. 当测试失败时,测试应该对问题提供尽可能多的信息。Google C++测试框架不在第一个测试失败时停止测试。相反,测试仅停止当前测试,然后继续下一个测试。你可以构建非致命失败报告的测试,当前测试在非致命失败产生后仍继续运行。因此,你可以在一次运行-编辑-编译循环中发现和修订大量bugs。
- The testing framework should liberate test writers from housekeeping chores and let them focus on the test content. Google C++ Testing Framework automatically keeps track of all tests defined, and doesn't require the user to enumerate them in order to run them. Testing framework应该把测试编写者从大量杂务事情中解放出来,使测试编写者更加关注测试内容。Google C++测试框架自动跟踪所有定义的测试,不需要用户为运行测试而去枚举测试。
- Tests should be fast. With Google C++ Testing Framework, you can reuse shared resources across tests and pay for the set-up/tear-down only once, without making tests depend on each other. 测试应该是快速的,使用Google C++测试框架,你可以在跨测试中重复使用共享资源,仅需一次构建/拆毁的开销,而并不需要在测试之间发生相互依赖。
Since Google C++ Testing Framework is based on the popular xUnit architecture, you'll feel right at home if you've used JUnit or PyUnit before. If not, it will take you about 10 minutes to learn the basics and get started. So let's go! 由于Google C++测试框架是基于流行的xUnit测试构架,因此如果之前使用过JUnit或PyUnit,你将会感到非常熟悉。如果之前没有用过JUnit或PyUnit,花费大约10分钟去学习基础概念和开始使用。好的,我们开始吧!
(我读完这篇文档花费了足足花了好几个小时,10分钟对于我们这些非英语为母语的技术员是不太可能的,估计是google为了表明自己的测试框架是多么的简单,吸引更多的技术员而采取的一种夸张的说法。)
Note: We occasionally refer to Google C++ Testing Framework informally as Google Test.