blob: 206164e061c709d136511d85c5d2843c4b521ce3 [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//
Todd Wang60052d82015-05-22 15:00:10 -070017// V23Init can be used within test functions as a safe alternative to v23.Init.
Cosmos Nicolaoua18a1eb2015-03-12 13:15:01 -070018//
19// func TestFoo(t *testing.T) {
Todd Wang60052d82015-05-22 15:00:10 -070020// ctx, shutdown := test.V23Init()
Cosmos Nicolaoua18a1eb2015-03-12 13:15:01 -070021// defer shutdown()
22// ...
23// }
Cosmos Nicolaou52e9a222015-03-16 21:57:16 -070024//
25// This package also defines flags for enabling and controlling
26// the v23 integration tests in package v23tests:
27// --v23.tests - run the integration tests
28// --v23.tests.shell-on-fail - drop into a debug shell if the test fails.
29//
30// Typical usage is:
31// $ v23 go test . --v23.tests
32//
33// Note that, like all flags not recognised by the go testing package, the
34// v23.tests flags must follow the package spec.
35//
36// The sub-directories of this package provide either functionality that
37// can be used within traditional go tests, or support for the v23 integration
38// test framework. The v23 command is able to generate boilerplate code
39// to support these tests. In summary, v23 test generate will generate
40// go files to be checked in that include appropriate TestMain functions,
41// registration calls for modules commands and wrapper functions for v23test
42// tests. More detailed documentation is available via:
43//
44// $ v23 test generate --help
45//
46// Vanadium tests often need to run subprocesses to provide either common
47// services that they depend (e.g. a mount table) and/or services that are
48// specific to the tests. The modules and v23tests subdirectories contain
49// packages that simplify this process.
50//
51// The subdirectories are:
52// benchmark - support for writing benchmarks.
53// testutil - utility functions used in tests.
54// security - security related utility functions used in tests.
55// timekeeper - an implementation of the timekeeper interface for use within
56// tests.
57// modules - support for running subprocesses using a single binary
58// v23tests - support for integration tests, including compiling and running
59// arbirtrary go code and pre-existing system commands.
60// expect - support for testing the contents of input streams. The methods
61// provided are embedded in the types used by modules and v23tests
62// so this package is generally not used directly.
Cosmos Nicolaou1381f8a2015-03-13 09:40:34 -070063package test