| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 5 |
|
| 6 |
<title>testing - The Go Programming Language</title> |
| 7 |
|
| 8 |
<link type="text/css" rel="stylesheet" href="/doc/style.css"> |
| 9 |
<script type="text/javascript" src="/doc/godocs.js"></script> |
| 10 |
|
| 11 |
<link rel="search" type="application/opensearchdescription+xml" title="godoc" href="/opensearch.xml" /> |
| 12 |
|
| 13 |
<script type="text/javascript"> |
| 14 |
var _gaq = _gaq || []; |
| 15 |
_gaq.push(["_setAccount", "UA-11222381-2"]); |
| 16 |
_gaq.push(["_trackPageview"]); |
| 17 |
</script> |
| 18 |
</head> |
| 19 |
<body> |
| 20 |
|
| 21 |
<div id="topbar"><div class="container wide"> |
| 22 |
|
| 23 |
<form method="GET" action="/search"> |
| 24 |
<div id="menu"> |
| 25 |
<a href="/doc/">Documents</a> |
| 26 |
<a href="/ref/">References</a> |
| 27 |
<a href="/pkg/">Packages</a> |
| 28 |
<a href="/project/">The Project</a> |
| 29 |
<a href="/help/">Help</a> |
| 30 |
<input type="text" id="search" name="q" class="inactive" value="Search"> |
| 31 |
</div> |
| 32 |
<div id="heading"><a href="/">The Go Programming Language</a></div> |
| 33 |
</form> |
| 34 |
|
| 35 |
</div></div> |
| 36 |
|
| 37 |
<div id="page" class="wide"> |
| 38 |
|
| 39 |
|
| 40 |
<div id="plusone"><g:plusone size="small" annotation="none"></g:plusone></div> |
| 41 |
<h1>Package testing</h1> |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
<div id="nav"></div> |
| 47 |
|
| 48 |
|
| 49 |
<!-- |
| 50 |
Copyright 2009 The Go Authors. All rights reserved. |
| 51 |
Use of this source code is governed by a BSD-style |
| 52 |
license that can be found in the LICENSE file. |
| 53 |
--> |
| 54 |
|
| 55 |
|
| 56 |
<div id="short-nav"> |
| 57 |
<dl> |
| 58 |
<dd><code>import "testing"</code></dd> |
| 59 |
</dl> |
| 60 |
<dl> |
| 61 |
<dd><a href="#overview" class="overviewLink">Overview</a></dd> |
| 62 |
<dd><a href="#index">Index</a></dd> |
| 63 |
|
| 64 |
|
| 65 |
<dd><a href="#subdirectories">Subdirectories</a></dd> |
| 66 |
|
| 67 |
</dl> |
| 68 |
</div> |
| 69 |
<!-- The package's Name is printed as title by the top-level template --> |
| 70 |
<div id="overview" class="toggleVisible"> |
| 71 |
<div class="collapsed"> |
| 72 |
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2> |
| 73 |
</div> |
| 74 |
<div class="expanded"> |
| 75 |
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2> |
| 76 |
<p> |
| 77 |
Package testing provides support for automated testing of Go packages. |
| 78 |
It is intended to be used in concert with the “go test” command, which automates |
| 79 |
execution of any function of the form |
| 80 |
</p> |
| 81 |
<pre>func TestXxx(*testing.T) |
| 82 |
</pre> |
| 83 |
<p> |
| 84 |
where Xxx can be any alphanumeric string (but the first letter must not be in |
| 85 |
[a-z]) and serves to identify the test routine. |
| 86 |
These TestXxx routines should be declared within the package they are testing. |
| 87 |
</p> |
| 88 |
<p> |
| 89 |
Functions of the form |
| 90 |
</p> |
| 91 |
<pre>func BenchmarkXxx(*testing.B) |
| 92 |
</pre> |
| 93 |
<p> |
| 94 |
are considered benchmarks, and are executed by the "go test" command when |
| 95 |
the -test.bench flag is provided. |
| 96 |
</p> |
| 97 |
<p> |
| 98 |
A sample benchmark function looks like this: |
| 99 |
</p> |
| 100 |
<pre>func BenchmarkHello(b *testing.B) { |
| 101 |
for i := 0; i < b.N; i++ { |
| 102 |
fmt.Sprintf("hello") |
| 103 |
} |
| 104 |
} |
| 105 |
</pre> |
| 106 |
<p> |
| 107 |
The benchmark package will vary b.N until the benchmark function lasts |
| 108 |
long enough to be timed reliably. The output |
| 109 |
</p> |
| 110 |
<pre>testing.BenchmarkHello 10000000 282 ns/op |
| 111 |
</pre> |
| 112 |
<p> |
| 113 |
means that the loop ran 10000000 times at a speed of 282 ns per loop. |
| 114 |
</p> |
| 115 |
<p> |
| 116 |
If a benchmark needs some expensive setup before running, the timer |
| 117 |
may be stopped: |
| 118 |
</p> |
| 119 |
<pre>func BenchmarkBigLen(b *testing.B) { |
| 120 |
b.StopTimer() |
| 121 |
big := NewBig() |
| 122 |
b.StartTimer() |
| 123 |
for i := 0; i < b.N; i++ { |
| 124 |
big.Len() |
| 125 |
} |
| 126 |
} |
| 127 |
</pre> |
| 128 |
<p> |
| 129 |
The package also runs and verifies example code. Example functions may |
| 130 |
include a concluding comment that begins with "Output:" and is compared with |
| 131 |
the standard output of the function when the tests are run, as in these |
| 132 |
examples of an example: |
| 133 |
</p> |
| 134 |
<pre>func ExampleHello() { |
| 135 |
fmt.Println("hello") |
| 136 |
// Output: hello |
| 137 |
} |
| 138 |
|
| 139 |
func ExampleSalutations() { |
| 140 |
fmt.Println("hello, and") |
| 141 |
fmt.Println("goodbye") |
| 142 |
// Output: |
| 143 |
// hello, and |
| 144 |
// goodbye |
| 145 |
} |
| 146 |
</pre> |
| 147 |
<p> |
| 148 |
Example functions without output comments are compiled but not executed. |
| 149 |
</p> |
| 150 |
<p> |
| 151 |
The naming convention to declare examples for a function F, a type T and |
| 152 |
method M on type T are: |
| 153 |
</p> |
| 154 |
<pre>func ExampleF() { ... } |
| 155 |
func ExampleT() { ... } |
| 156 |
func ExampleT_M() { ... } |
| 157 |
</pre> |
| 158 |
<p> |
| 159 |
Multiple example functions for a type/function/method may be provided by |
| 160 |
appending a distinct suffix to the name. The suffix must start with a |
| 161 |
lower-case letter. |
| 162 |
</p> |
| 163 |
<pre>func ExampleF_suffix() { ... } |
| 164 |
func ExampleT_suffix() { ... } |
| 165 |
func ExampleT_M_suffix() { ... } |
| 166 |
</pre> |
| 167 |
<p> |
| 168 |
The entire test file is presented as the example when it contains a single |
| 169 |
example function, at least one other function, type, variable, or constant |
| 170 |
declaration, and no test or benchmark functions. |
| 171 |
</p> |
| 172 |
|
| 173 |
</div> |
| 174 |
</div> |
| 175 |
|
| 176 |
|
| 177 |
<h2 id="index">Index</h2> |
| 178 |
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. --> |
| 179 |
<div id="manual-nav"> |
| 180 |
<dl> |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
<dd><a href="#Main">func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample)</a></dd> |
| 186 |
|
| 187 |
|
| 188 |
<dd><a href="#RunBenchmarks">func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark)</a></dd> |
| 189 |
|
| 190 |
|
| 191 |
<dd><a href="#RunExamples">func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool)</a></dd> |
| 192 |
|
| 193 |
|
| 194 |
<dd><a href="#RunTests">func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool)</a></dd> |
| 195 |
|
| 196 |
|
| 197 |
<dd><a href="#Short">func Short() bool</a></dd> |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
<dd><a href="#B">type B</a></dd> |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
<dd> <a href="#B.Error">func (c *B) Error(args ...interface{})</a></dd> |
| 206 |
|
| 207 |
|
| 208 |
<dd> <a href="#B.Errorf">func (c *B) Errorf(format string, args ...interface{})</a></dd> |
| 209 |
|
| 210 |
|
| 211 |
<dd> <a href="#B.Fail">func (c *B) Fail()</a></dd> |
| 212 |
|
| 213 |
|
| 214 |
<dd> <a href="#B.FailNow">func (c *B) FailNow()</a></dd> |
| 215 |
|
| 216 |
|
| 217 |
<dd> <a href="#B.Failed">func (c *B) Failed() bool</a></dd> |
| 218 |
|
| 219 |
|
| 220 |
<dd> <a href="#B.Fatal">func (c *B) Fatal(args ...interface{})</a></dd> |
| 221 |
|
| 222 |
|
| 223 |
<dd> <a href="#B.Fatalf">func (c *B) Fatalf(format string, args ...interface{})</a></dd> |
| 224 |
|
| 225 |
|
| 226 |
<dd> <a href="#B.Log">func (c *B) Log(args ...interface{})</a></dd> |
| 227 |
|
| 228 |
|
| 229 |
<dd> <a href="#B.Logf">func (c *B) Logf(format string, args ...interface{})</a></dd> |
| 230 |
|
| 231 |
|
| 232 |
<dd> <a href="#B.ResetTimer">func (b *B) ResetTimer()</a></dd> |
| 233 |
|
| 234 |
|
| 235 |
<dd> <a href="#B.SetBytes">func (b *B) SetBytes(n int64)</a></dd> |
| 236 |
|
| 237 |
|
| 238 |
<dd> <a href="#B.StartTimer">func (b *B) StartTimer()</a></dd> |
| 239 |
|
| 240 |
|
| 241 |
<dd> <a href="#B.StopTimer">func (b *B) StopTimer()</a></dd> |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
<dd><a href="#BenchmarkResult">type BenchmarkResult</a></dd> |
| 246 |
|
| 247 |
|
| 248 |
<dd> <a href="#Benchmark">func Benchmark(f func(b *B)) BenchmarkResult</a></dd> |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
<dd> <a href="#BenchmarkResult.NsPerOp">func (r BenchmarkResult) NsPerOp() int64</a></dd> |
| 253 |
|
| 254 |
|
| 255 |
<dd> <a href="#BenchmarkResult.String">func (r BenchmarkResult) String() string</a></dd> |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
<dd><a href="#InternalBenchmark">type InternalBenchmark</a></dd> |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
<dd><a href="#InternalExample">type InternalExample</a></dd> |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
<dd><a href="#InternalTest">type InternalTest</a></dd> |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
<dd><a href="#T">type T</a></dd> |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
<dd> <a href="#T.Error">func (c *T) Error(args ...interface{})</a></dd> |
| 279 |
|
| 280 |
|
| 281 |
<dd> <a href="#T.Errorf">func (c *T) Errorf(format string, args ...interface{})</a></dd> |
| 282 |
|
| 283 |
|
| 284 |
<dd> <a href="#T.Fail">func (c *T) Fail()</a></dd> |
| 285 |
|
| 286 |
|
| 287 |
<dd> <a href="#T.FailNow">func (c *T) FailNow()</a></dd> |
| 288 |
|
| 289 |
|
| 290 |
<dd> <a href="#T.Failed">func (c *T) Failed() bool</a></dd> |
| 291 |
|
| 292 |
|
| 293 |
<dd> <a href="#T.Fatal">func (c *T) Fatal(args ...interface{})</a></dd> |
| 294 |
|
| 295 |
|
| 296 |
<dd> <a href="#T.Fatalf">func (c *T) Fatalf(format string, args ...interface{})</a></dd> |
| 297 |
|
| 298 |
|
| 299 |
<dd> <a href="#T.Log">func (c *T) Log(args ...interface{})</a></dd> |
| 300 |
|
| 301 |
|
| 302 |
<dd> <a href="#T.Logf">func (c *T) Logf(format string, args ...interface{})</a></dd> |
| 303 |
|
| 304 |
|
| 305 |
<dd> <a href="#T.Parallel">func (t *T) Parallel()</a></dd> |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
</dl> |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
<h4>Package files</h4> |
| 315 |
<p> |
| 316 |
<span style="font-size:90%"> |
| 317 |
|
| 318 |
<a href="/src/pkg/testing/benchmark.go">benchmark.go</a> |
| 319 |
|
| 320 |
<a href="/src/pkg/testing/example.go">example.go</a> |
| 321 |
|
| 322 |
<a href="/src/pkg/testing/testing.go">testing.go</a> |
| 323 |
|
| 324 |
</span> |
| 325 |
</p> |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
<h2 id="Main">func <a href="/src/pkg/testing/testing.go?s=9750:9890#L268">Main</a></h2> |
| 334 |
<pre>func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample)</pre> |
| 335 |
<p> |
| 336 |
An internal function but exported because it is cross-package; part of the implementation |
| 337 |
of the "go test" command. |
| 338 |
</p> |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
<h2 id="RunBenchmarks">func <a href="/src/pkg/testing/benchmark.go?s=5365:5464#L207">RunBenchmarks</a></h2> |
| 345 |
<pre>func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark)</pre> |
| 346 |
<p> |
| 347 |
An internal function but exported because it is cross-package; part of the implementation |
| 348 |
of the "go test" command. |
| 349 |
</p> |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
<h2 id="RunExamples">func <a href="/src/pkg/testing/example.go?s=314:417#L12">RunExamples</a></h2> |
| 356 |
<pre>func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool)</pre> |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
<h2 id="RunTests">func <a href="/src/pkg/testing/testing.go?s=10486:10580#L297">RunTests</a></h2> |
| 363 |
<pre>func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool)</pre> |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
<h2 id="Short">func <a href="/src/pkg/testing/testing.go?s=4859:4876#L117">Short</a></h2> |
| 370 |
<pre>func Short() bool</pre> |
| 371 |
<p> |
| 372 |
Short reports whether the -test.short flag is set. |
| 373 |
</p> |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
<h2 id="B">type <a href="/src/pkg/testing/benchmark.go?s=743:872#L17">B</a></h2> |
| 381 |
<pre>type B struct { |
| 382 |
N int |
| 383 |
<span class="comment">// contains filtered or unexported fields</span> |
| 384 |
}</pre> |
| 385 |
<p> |
| 386 |
B is a type passed to Benchmark functions to manage benchmark |
| 387 |
timing and to specify the number of iterations to run. |
| 388 |
</p> |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
<h3 id="B.Error">func (*B) <a href="/src/pkg/testing/testing.go?s=8110:8153#L209">Error</a></h3> |
| 402 |
<pre>func (c *B) Error(args ...interface{})</pre> |
| 403 |
<p> |
| 404 |
Error is equivalent to Log() followed by Fail(). |
| 405 |
</p> |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
<h3 id="B.Errorf">func (*B) <a href="/src/pkg/testing/testing.go?s=8253:8312#L215">Errorf</a></h3> |
| 412 |
<pre>func (c *B) Errorf(format string, args ...interface{})</pre> |
| 413 |
<p> |
| 414 |
Errorf is equivalent to Logf() followed by Fail(). |
| 415 |
</p> |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
<h3 id="B.Fail">func (*B) <a href="/src/pkg/testing/testing.go?s=6270:6293#L163">Fail</a></h3> |
| 422 |
<pre>func (c *B) Fail()</pre> |
| 423 |
<p> |
| 424 |
Fail marks the function as having failed but continues execution. |
| 425 |
</p> |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
<h3 id="B.FailNow">func (*B) <a href="/src/pkg/testing/testing.go?s=6548:6574#L170">FailNow</a></h3> |
| 432 |
<pre>func (c *B) FailNow()</pre> |
| 433 |
<p> |
| 434 |
FailNow marks the function as having failed and stops its execution. |
| 435 |
Execution will continue at the next test or benchmark. |
| 436 |
</p> |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
<h3 id="B.Failed">func (*B) <a href="/src/pkg/testing/testing.go?s=6366:6396#L166">Failed</a></h3> |
| 443 |
<pre>func (c *B) Failed() bool</pre> |
| 444 |
<p> |
| 445 |
Failed returns whether the function has failed. |
| 446 |
</p> |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
<h3 id="B.Fatal">func (*B) <a href="/src/pkg/testing/testing.go?s=8420:8463#L221">Fatal</a></h3> |
| 453 |
<pre>func (c *B) Fatal(args ...interface{})</pre> |
| 454 |
<p> |
| 455 |
Fatal is equivalent to Log() followed by FailNow(). |
| 456 |
</p> |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
<h3 id="B.Fatalf">func (*B) <a href="/src/pkg/testing/testing.go?s=8569:8628#L227">Fatalf</a></h3> |
| 463 |
<pre>func (c *B) Fatalf(format string, args ...interface{})</pre> |
| 464 |
<p> |
| 465 |
Fatalf is equivalent to Logf() followed by FailNow(). |
| 466 |
</p> |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
<h3 id="B.Log">func (*B) <a href="/src/pkg/testing/testing.go?s=7763:7804#L202">Log</a></h3> |
| 473 |
<pre>func (c *B) Log(args ...interface{})</pre> |
| 474 |
<p> |
| 475 |
Log formats its arguments using default formatting, analogous to Println(), |
| 476 |
and records the text in the error log. |
| 477 |
</p> |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
<h3 id="B.Logf">func (*B) <a href="/src/pkg/testing/testing.go?s=7959:8016#L206">Logf</a></h3> |
| 484 |
<pre>func (c *B) Logf(format string, args ...interface{})</pre> |
| 485 |
<p> |
| 486 |
Logf formats its arguments according to the format, analogous to Printf(), |
| 487 |
and records the text in the error log. |
| 488 |
</p> |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
<h3 id="B.ResetTimer">func (*B) <a href="/src/pkg/testing/benchmark.go?s=1503:1527#L48">ResetTimer</a></h3> |
| 495 |
<pre>func (b *B) ResetTimer()</pre> |
| 496 |
<p> |
| 497 |
ResetTimer sets the elapsed benchmark time to zero. |
| 498 |
It does not affect whether the timer is running. |
| 499 |
</p> |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
<h3 id="B.SetBytes">func (*B) <a href="/src/pkg/testing/benchmark.go?s=1728:1757#L57">SetBytes</a></h3> |
| 506 |
<pre>func (b *B) SetBytes(n int64)</pre> |
| 507 |
<p> |
| 508 |
SetBytes records the number of bytes processed in a single operation. |
| 509 |
If this is called, the benchmark will report ns/op and MB/s. |
| 510 |
</p> |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
<h3 id="B.StartTimer">func (*B) <a href="/src/pkg/testing/benchmark.go?s=1047:1071#L29">StartTimer</a></h3> |
| 517 |
<pre>func (b *B) StartTimer()</pre> |
| 518 |
<p> |
| 519 |
StartTimer starts timing a test. This function is called automatically |
| 520 |
before a benchmark starts, but it can also used to resume timing after |
| 521 |
a call to StopTimer. |
| 522 |
</p> |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
<h3 id="B.StopTimer">func (*B) <a href="/src/pkg/testing/benchmark.go?s=1288:1311#L39">StopTimer</a></h3> |
| 529 |
<pre>func (b *B) StopTimer()</pre> |
| 530 |
<p> |
| 531 |
StopTimer stops timing a test. This can be used to pause the timer |
| 532 |
while performing complex initialization that you don't |
| 533 |
want to measure. |
| 534 |
</p> |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
<h2 id="BenchmarkResult">type <a href="/src/pkg/testing/benchmark.go?s=4206:4391#L165">BenchmarkResult</a></h2> |
| 543 |
<pre>type BenchmarkResult struct { |
| 544 |
N int <span class="comment">// The number of iterations.</span> |
| 545 |
T time.Duration <span class="comment">// The total time taken.</span> |
| 546 |
Bytes int64 <span class="comment">// Bytes processed in one iteration.</span> |
| 547 |
}</pre> |
| 548 |
<p> |
| 549 |
The results of a benchmark run. |
| 550 |
</p> |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
<h3 id="Benchmark">func <a href="/src/pkg/testing/benchmark.go?s=7545:7589#L275">Benchmark</a></h3> |
| 562 |
<pre>func Benchmark(f func(b *B)) BenchmarkResult</pre> |
| 563 |
<p> |
| 564 |
Benchmark benchmarks a single function. Useful for creating |
| 565 |
custom benchmarks that do not use the "go test" command. |
| 566 |
</p> |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
<h3 id="BenchmarkResult.NsPerOp">func (BenchmarkResult) <a href="/src/pkg/testing/benchmark.go?s=4393:4433#L171">NsPerOp</a></h3> |
| 574 |
<pre>func (r BenchmarkResult) NsPerOp() int64</pre> |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
<h3 id="BenchmarkResult.String">func (BenchmarkResult) <a href="/src/pkg/testing/benchmark.go?s=4677:4717#L185">String</a></h3> |
| 581 |
<pre>func (r BenchmarkResult) String() string</pre> |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
<h2 id="InternalBenchmark">type <a href="/src/pkg/testing/benchmark.go?s=555:618#L10">InternalBenchmark</a></h2> |
| 590 |
<pre>type InternalBenchmark struct { |
| 591 |
Name string |
| 592 |
F func(b *B) |
| 593 |
}</pre> |
| 594 |
<p> |
| 595 |
An internal type but exported because it is cross-package; part of the implementation |
| 596 |
of the "go test" command. |
| 597 |
</p> |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
<h2 id="InternalExample">type <a href="/src/pkg/testing/example.go?s=236:312#L6">InternalExample</a></h2> |
| 613 |
<pre>type InternalExample struct { |
| 614 |
Name string |
| 615 |
F func() |
| 616 |
Output string |
| 617 |
}</pre> |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
<h2 id="InternalTest">type <a href="/src/pkg/testing/testing.go?s=9065:9121#L241">InternalTest</a></h2> |
| 633 |
<pre>type InternalTest struct { |
| 634 |
Name string |
| 635 |
F func(*T) |
| 636 |
}</pre> |
| 637 |
<p> |
| 638 |
An internal type but exported because it is cross-package; part of the implementation |
| 639 |
of the "go test" command. |
| 640 |
</p> |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
<h2 id="T">type <a href="/src/pkg/testing/testing.go?s=6070:6199#L156">T</a></h2> |
| 656 |
<pre>type T struct { |
| 657 |
<span class="comment">// contains filtered or unexported fields</span> |
| 658 |
}</pre> |
| 659 |
<p> |
| 660 |
T is a type passed to Test functions to manage test state and support formatted test logs. |
| 661 |
Logs are accumulated during execution and dumped to standard error when done. |
| 662 |
</p> |
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
<h3 id="T.Error">func (*T) <a href="/src/pkg/testing/testing.go?s=8110:8153#L209">Error</a></h3> |
| 676 |
<pre>func (c *T) Error(args ...interface{})</pre> |
| 677 |
<p> |
| 678 |
Error is equivalent to Log() followed by Fail(). |
| 679 |
</p> |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
<h3 id="T.Errorf">func (*T) <a href="/src/pkg/testing/testing.go?s=8253:8312#L215">Errorf</a></h3> |
| 686 |
<pre>func (c *T) Errorf(format string, args ...interface{})</pre> |
| 687 |
<p> |
| 688 |
Errorf is equivalent to Logf() followed by Fail(). |
| 689 |
</p> |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
<h3 id="T.Fail">func (*T) <a href="/src/pkg/testing/testing.go?s=6270:6293#L163">Fail</a></h3> |
| 696 |
<pre>func (c *T) Fail()</pre> |
| 697 |
<p> |
| 698 |
Fail marks the function as having failed but continues execution. |
| 699 |
</p> |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
<h3 id="T.FailNow">func (*T) <a href="/src/pkg/testing/testing.go?s=6548:6574#L170">FailNow</a></h3> |
| 706 |
<pre>func (c *T) FailNow()</pre> |
| 707 |
<p> |
| 708 |
FailNow marks the function as having failed and stops its execution. |
| 709 |
Execution will continue at the next test or benchmark. |
| 710 |
</p> |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
<h3 id="T.Failed">func (*T) <a href="/src/pkg/testing/testing.go?s=6366:6396#L166">Failed</a></h3> |
| 717 |
<pre>func (c *T) Failed() bool</pre> |
| 718 |
<p> |
| 719 |
Failed returns whether the function has failed. |
| 720 |
</p> |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
<h3 id="T.Fatal">func (*T) <a href="/src/pkg/testing/testing.go?s=8420:8463#L221">Fatal</a></h3> |
| 727 |
<pre>func (c *T) Fatal(args ...interface{})</pre> |
| 728 |
<p> |
| 729 |
Fatal is equivalent to Log() followed by FailNow(). |
| 730 |
</p> |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
<h3 id="T.Fatalf">func (*T) <a href="/src/pkg/testing/testing.go?s=8569:8628#L227">Fatalf</a></h3> |
| 737 |
<pre>func (c *T) Fatalf(format string, args ...interface{})</pre> |
| 738 |
<p> |
| 739 |
Fatalf is equivalent to Logf() followed by FailNow(). |
| 740 |
</p> |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
<h3 id="T.Log">func (*T) <a href="/src/pkg/testing/testing.go?s=7763:7804#L202">Log</a></h3> |
| 747 |
<pre>func (c *T) Log(args ...interface{})</pre> |
| 748 |
<p> |
| 749 |
Log formats its arguments using default formatting, analogous to Println(), |
| 750 |
and records the text in the error log. |
| 751 |
</p> |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
<h3 id="T.Logf">func (*T) <a href="/src/pkg/testing/testing.go?s=7959:8016#L206">Logf</a></h3> |
| 758 |
<pre>func (c *T) Logf(format string, args ...interface{})</pre> |
| 759 |
<p> |
| 760 |
Logf formats its arguments according to the format, analogous to Printf(), |
| 761 |
and records the text in the error log. |
| 762 |
</p> |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
<h3 id="T.Parallel">func (*T) <a href="/src/pkg/testing/testing.go?s=8809:8831#L234">Parallel</a></h3> |
| 769 |
<pre>func (t *T) Parallel()</pre> |
| 770 |
<p> |
| 771 |
Parallel signals that this test is to be run in parallel with (and only with) |
| 772 |
other parallel tests in this CPU group. |
| 773 |
</p> |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
</div> |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
<h2 id="subdirectories">Subdirectories</h2> |
| 793 |
|
| 794 |
<table class="dir"> |
| 795 |
<tr> |
| 796 |
<th>Name</th> |
| 797 |
<th> </th> |
| 798 |
<th style="text-align: left; width: auto">Synopsis</th> |
| 799 |
</tr> |
| 800 |
|
| 801 |
<tr> |
| 802 |
<td><a href="..">..</a></td> |
| 803 |
</tr> |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
<tr> |
| 808 |
<td class="name"><a href="iotest">iotest</a></td> |
| 809 |
<td> </td> |
| 810 |
<td style="width: auto">Package iotest implements Readers and Writers useful mainly for testing.</td> |
| 811 |
</tr> |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
<tr> |
| 816 |
<td class="name"><a href="quick">quick</a></td> |
| 817 |
<td> </td> |
| 818 |
<td style="width: auto">Package quick implements utility functions to help with black box testing.</td> |
| 819 |
</tr> |
| 820 |
|
| 821 |
|
| 822 |
</table> |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
</div> |
| 828 |
|
| 829 |
<div id="footer"> |
| 830 |
Build version go1.0.2.<br> |
| 831 |
Except as <a href="http://code.google.com/policies.html#restrictions">noted</a>, |
| 832 |
the content of this page is licensed under the |
| 833 |
Creative Commons Attribution 3.0 License, |
| 834 |
and code is licensed under a <a href="/LICENSE">BSD license</a>.<br> |
| 835 |
<a href="/doc/tos.html">Terms of Service</a> | |
| 836 |
<a href="http://www.google.com/intl/en/privacy/privacy-policy.html">Privacy Policy</a> |
| 837 |
</div> |
| 838 |
|
| 839 |
<script type="text/javascript"> |
| 840 |
(function() { |
| 841 |
var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true; |
| 842 |
ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js"; |
| 843 |
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s); |
| 844 |
})(); |
| 845 |
</script> |
| 846 |
</body> |
| 847 |
<script type="text/javascript"> |
| 848 |
(function() { |
| 849 |
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; |
| 850 |
po.src = 'https://apis.google.com/js/plusone.js'; |
| 851 |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); |
| 852 |
})(); |
| 853 |
</script> |
| 854 |
</html> |
| 855 |
|