]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/doc/introduction/introduction.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / doc / introduction / introduction.qbk
1 [/
2 / Copyright (c) 2003 Boost.Test contributors
3 /
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 /]
7
8
9 [section:intro Introduction]
10
11 [role epigraph Test everything that could possibly break]
12 [role epigraph --XP maxim]
13
14 [role epigraph
15 The acceptance test makes the customer satisfied
16 that the software provides the business value that
17 makes them willing to pay for it. The unit test makes
18 the programmer satisfied that the software does what
19 the programmer thinks it does
20 ]
21 [role epigraph --XP maxim]
22
23 What is the first thing you need to do when you start working on new library/class/program? That's right -
24 you need to start with the unit test module (hopefully you all gave this answer!). Occasionally, you may get
25 away with simple test implemented using `assert`s, but any professional developer soon finds this approach
26 lacking. It becomes clear that it's too time-consuming and tedious for simple, but repetitive unit testing
27 tasks and it's too inflexible for most non-trivial ones.
28
29 The Boost.Test library provides both an easy to use and flexible set of interfaces for writing test
30 programs, organizing tests into simple test cases and test suites, and controlling their runtime execution.
31 Some of Boost.Test's interfaces are also useful in production (non-test) environments.
32
33 [/ ##################################################################### ]
34
35 [h4 Starter example]
36
37 This is how a minimal single-file test program looks like:
38
39 ``
40 #define __BOOST_TEST_MODULE__ My Test /*< Macro __BOOST_TEST_MODULE__ defines the name of our program, which will be used in messages. >*/
41 #include <boost/test/included/unit_test.hpp> /*< This includes all the __UTF__ in a "single header mode"; it even defines function `main`, which will call the subsequently defined test cases. >*/
42
43 __BOOST_AUTO_TEST_CASE__(first_test) /*< Macro __BOOST_AUTO_TEST_CASE__ declares a ['test case] named `first_test`, which in turn will run the content of `first_test` inside the
44 controlled testing environment.>*/
45 {
46 int i = 1;
47 __BOOST_TEST__(i); /*< This test checks if `i` is non-zero. >*/
48 __BOOST_TEST__(i == 2); /*< This test checks if `i` has value `2` (something more than just evaluating the equality operator). >*/
49 }
50 ``
51
52 When run, it produces the following output:
53
54 [pre
55 Running 1 test case...
56 test_file.cpp(8): error: in "first_test": check i == 2 has failed [1 != 2]
57
58 *** 1 failure is detected in the test module "My Test"
59 ]
60
61 [/ ##################################################################### ]
62
63 [include overview.qbk]
64
65
66 [endsect]
67
68 [/ EOF]