blob: cb84f2b330c526adb9864de9c0203b0681578d29 [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// 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 Wang8c4e5cc2015-04-09 11:30:52 -07005// Package test implements initalization for unit and integration tests.
Cosmos Nicolaoua18a1eb2015-03-12 13:15:01 -07006//
Cosmos Nicolaou52e9a222015-03-16 21:57:16 -07007// Init configures logging, random number generators and other global state.
Cosmos Nicolaoua18a1eb2015-03-12 13:15:01 -07008// Typical usage in _test.go files:
9//
Cosmos Nicolaou1381f8a2015-03-13 09:40:34 -070010// import "v.io/x/ref/test"
Cosmos Nicolaou52e9a222015-03-16 21:57:16 -070011//
Cosmos Nicolaoua18a1eb2015-03-12 13:15:01 -070012// func TestMain(m *testing.M) {
Cosmos Nicolaou1381f8a2015-03-13 09:40:34 -070013// test.Init()
Cosmos Nicolaoua18a1eb2015-03-12 13:15:01 -070014// 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 Nicolaou1381f8a2015-03-13 09:40:34 -070021// ctx, shutdown := test.InitForTest()
Cosmos Nicolaoua18a1eb2015-03-12 13:15:01 -070022// defer shutdown()
23// ...
24// }
Cosmos Nicolaou52e9a222015-03-16 21:57:16 -070025//
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 Nicolaou1381f8a2015-03-13 09:40:34 -070064package test