Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Todd Wang | 8c4e5cc | 2015-04-09 11:30:52 -0700 | [diff] [blame] | 5 | // Package test implements initalization for unit and integration tests. |
Cosmos Nicolaou | a18a1eb | 2015-03-12 13:15:01 -0700 | [diff] [blame] | 6 | // |
Cosmos Nicolaou | 52e9a22 | 2015-03-16 21:57:16 -0700 | [diff] [blame] | 7 | // Init configures logging, random number generators and other global state. |
Cosmos Nicolaou | a18a1eb | 2015-03-12 13:15:01 -0700 | [diff] [blame] | 8 | // Typical usage in _test.go files: |
| 9 | // |
Cosmos Nicolaou | 1381f8a | 2015-03-13 09:40:34 -0700 | [diff] [blame] | 10 | // import "v.io/x/ref/test" |
Cosmos Nicolaou | 52e9a22 | 2015-03-16 21:57:16 -0700 | [diff] [blame] | 11 | // |
Cosmos Nicolaou | a18a1eb | 2015-03-12 13:15:01 -0700 | [diff] [blame] | 12 | // func TestMain(m *testing.M) { |
Cosmos Nicolaou | 1381f8a | 2015-03-13 09:40:34 -0700 | [diff] [blame] | 13 | // test.Init() |
Cosmos Nicolaou | a18a1eb | 2015-03-12 13:15:01 -0700 | [diff] [blame] | 14 | // os.Exit(m.Run()) |
| 15 | // } |
| 16 | // |
| 17 | // InitForTest can be used within test functions as a safe alternative |
| 18 | // to v23.Init. |
| 19 | // |
| 20 | // func TestFoo(t *testing.T) { |
Cosmos Nicolaou | 1381f8a | 2015-03-13 09:40:34 -0700 | [diff] [blame] | 21 | // ctx, shutdown := test.InitForTest() |
Cosmos Nicolaou | a18a1eb | 2015-03-12 13:15:01 -0700 | [diff] [blame] | 22 | // defer shutdown() |
| 23 | // ... |
| 24 | // } |
Cosmos Nicolaou | 52e9a22 | 2015-03-16 21:57:16 -0700 | [diff] [blame] | 25 | // |
| 26 | // This package also defines flags for enabling and controlling |
| 27 | // the v23 integration tests in package v23tests: |
| 28 | // --v23.tests - run the integration tests |
| 29 | // --v23.tests.shell-on-fail - drop into a debug shell if the test fails. |
| 30 | // |
| 31 | // Typical usage is: |
| 32 | // $ v23 go test . --v23.tests |
| 33 | // |
| 34 | // Note that, like all flags not recognised by the go testing package, the |
| 35 | // v23.tests flags must follow the package spec. |
| 36 | // |
| 37 | // The sub-directories of this package provide either functionality that |
| 38 | // can be used within traditional go tests, or support for the v23 integration |
| 39 | // test framework. The v23 command is able to generate boilerplate code |
| 40 | // to support these tests. In summary, v23 test generate will generate |
| 41 | // go files to be checked in that include appropriate TestMain functions, |
| 42 | // registration calls for modules commands and wrapper functions for v23test |
| 43 | // tests. More detailed documentation is available via: |
| 44 | // |
| 45 | // $ v23 test generate --help |
| 46 | // |
| 47 | // Vanadium tests often need to run subprocesses to provide either common |
| 48 | // services that they depend (e.g. a mount table) and/or services that are |
| 49 | // specific to the tests. The modules and v23tests subdirectories contain |
| 50 | // packages that simplify this process. |
| 51 | // |
| 52 | // The subdirectories are: |
| 53 | // benchmark - support for writing benchmarks. |
| 54 | // testutil - utility functions used in tests. |
| 55 | // security - security related utility functions used in tests. |
| 56 | // timekeeper - an implementation of the timekeeper interface for use within |
| 57 | // tests. |
| 58 | // modules - support for running subprocesses using a single binary |
| 59 | // v23tests - support for integration tests, including compiling and running |
| 60 | // arbirtrary go code and pre-existing system commands. |
| 61 | // expect - support for testing the contents of input streams. The methods |
| 62 | // provided are embedded in the types used by modules and v23tests |
| 63 | // so this package is generally not used directly. |
Cosmos Nicolaou | 1381f8a | 2015-03-13 09:40:34 -0700 | [diff] [blame] | 64 | package test |