You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1622 lines
48 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>testing - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package testing</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "testing"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
  58. <dd><a href="index.html#pkg-subdirectories">Subdirectories</a></dd>
  59. </dl>
  60. </div>
  61. <!-- The package's Name is printed as title by the top-level template -->
  62. <div id="pkg-overview" class="toggleVisible">
  63. <div class="collapsed">
  64. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  65. </div>
  66. <div class="expanded">
  67. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  68. <p>
  69. Package testing provides support for automated testing of Go packages.
  70. It is intended to be used in concert with the &ldquo;go test&rdquo; command, which automates
  71. execution of any function of the form
  72. </p>
  73. <pre>func TestXxx(*testing.T)
  74. </pre>
  75. <p>
  76. where Xxx can be any alphanumeric string (but the first letter must not be in
  77. [a-z]) and serves to identify the test routine.
  78. </p>
  79. <p>
  80. Within these functions, use the Error, Fail or related methods to signal failure.
  81. </p>
  82. <p>
  83. To write a new test suite, create a file whose name ends _test.go that
  84. contains the TestXxx functions as described here. Put the file in the same
  85. package as the one being tested. The file will be excluded from regular
  86. package builds but will be included when the &ldquo;go test&rdquo; command is run.
  87. For more detail, run &ldquo;go help test&rdquo; and &ldquo;go help testflag&rdquo;.
  88. </p>
  89. <p>
  90. Tests and benchmarks may be skipped if not applicable with a call to
  91. the Skip method of *T and *B:
  92. </p>
  93. <pre>func TestTimeConsuming(t *testing.T) {
  94. if testing.Short() {
  95. t.Skip(&#34;skipping test in short mode.&#34;)
  96. }
  97. ...
  98. }
  99. </pre>
  100. <h3 id="hdr-Benchmarks">Benchmarks</h3>
  101. <p>
  102. Functions of the form
  103. </p>
  104. <pre>func BenchmarkXxx(*testing.B)
  105. </pre>
  106. <p>
  107. are considered benchmarks, and are executed by the &#34;go test&#34; command when
  108. its -bench flag is provided. Benchmarks are run sequentially.
  109. </p>
  110. <p>
  111. For a description of the testing flags, see
  112. <a href="https://golang.org/cmd/go/#hdr-Description_of_testing_flags">https://golang.org/cmd/go/#hdr-Description_of_testing_flags</a>.
  113. </p>
  114. <p>
  115. A sample benchmark function looks like this:
  116. </p>
  117. <pre>func BenchmarkHello(b *testing.B) {
  118. for i := 0; i &lt; b.N; i++ {
  119. fmt.Sprintf(&#34;hello&#34;)
  120. }
  121. }
  122. </pre>
  123. <p>
  124. The benchmark function must run the target code b.N times.
  125. During benchmark execution, b.N is adjusted until the benchmark function lasts
  126. long enough to be timed reliably. The output
  127. </p>
  128. <pre>BenchmarkHello 10000000 282 ns/op
  129. </pre>
  130. <p>
  131. means that the loop ran 10000000 times at a speed of 282 ns per loop.
  132. </p>
  133. <p>
  134. If a benchmark needs some expensive setup before running, the timer
  135. may be reset:
  136. </p>
  137. <pre>func BenchmarkBigLen(b *testing.B) {
  138. big := NewBig()
  139. b.ResetTimer()
  140. for i := 0; i &lt; b.N; i++ {
  141. big.Len()
  142. }
  143. }
  144. </pre>
  145. <p>
  146. If a benchmark needs to test performance in a parallel setting, it may use
  147. the RunParallel helper function; such benchmarks are intended to be used with
  148. the go test -cpu flag:
  149. </p>
  150. <pre>func BenchmarkTemplateParallel(b *testing.B) {
  151. templ := template.Must(template.New(&#34;test&#34;).Parse(&#34;Hello, {{.}}!&#34;))
  152. b.RunParallel(func(pb *testing.PB) {
  153. var buf bytes.Buffer
  154. for pb.Next() {
  155. buf.Reset()
  156. templ.Execute(&amp;buf, &#34;World&#34;)
  157. }
  158. })
  159. }
  160. </pre>
  161. <h3 id="hdr-Examples">Examples</h3>
  162. <p>
  163. The package also runs and verifies example code. Example functions may
  164. include a concluding line comment that begins with &#34;Output:&#34; and is compared with
  165. the standard output of the function when the tests are run. (The comparison
  166. ignores leading and trailing space.) These are examples of an example:
  167. </p>
  168. <pre>func ExampleHello() {
  169. fmt.Println(&#34;hello&#34;)
  170. // Output: hello
  171. }
  172. func ExampleSalutations() {
  173. fmt.Println(&#34;hello, and&#34;)
  174. fmt.Println(&#34;goodbye&#34;)
  175. // Output:
  176. // hello, and
  177. // goodbye
  178. }
  179. </pre>
  180. <p>
  181. Example functions without output comments are compiled but not executed.
  182. </p>
  183. <p>
  184. The naming convention to declare examples for the package, a function F, a type T and
  185. method M on type T are:
  186. </p>
  187. <pre>func Example() { ... }
  188. func ExampleF() { ... }
  189. func ExampleT() { ... }
  190. func ExampleT_M() { ... }
  191. </pre>
  192. <p>
  193. Multiple example functions for a package/type/function/method may be provided by
  194. appending a distinct suffix to the name. The suffix must start with a
  195. lower-case letter.
  196. </p>
  197. <pre>func Example_suffix() { ... }
  198. func ExampleF_suffix() { ... }
  199. func ExampleT_suffix() { ... }
  200. func ExampleT_M_suffix() { ... }
  201. </pre>
  202. <p>
  203. The entire test file is presented as the example when it contains a single
  204. example function, at least one other function, type, variable, or constant
  205. declaration, and no test or benchmark functions.
  206. </p>
  207. <h3 id="hdr-Main">Main</h3>
  208. <p>
  209. It is sometimes necessary for a test program to do extra setup or teardown
  210. before or after testing. It is also sometimes necessary for a test to control
  211. which code runs on the main thread. To support these and other cases,
  212. if a test file contains a function:
  213. </p>
  214. <pre>func TestMain(m *testing.M)
  215. </pre>
  216. <p>
  217. then the generated test will call TestMain(m) instead of running the tests
  218. directly. TestMain runs in the main goroutine and can do whatever setup
  219. and teardown is necessary around a call to m.Run. It should then call
  220. os.Exit with the result of m.Run. When TestMain is called, flag.Parse has
  221. not been run. If TestMain depends on command-line flags, including those
  222. of the testing package, it should call flag.Parse explicitly.
  223. </p>
  224. <p>
  225. A simple implementation of TestMain is:
  226. </p>
  227. <pre>func TestMain(m *testing.M) {
  228. flag.Parse()
  229. os.Exit(m.Run())
  230. }
  231. </pre>
  232. </div>
  233. </div>
  234. <div id="pkg-index" class="toggleVisible">
  235. <div class="collapsed">
  236. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  237. </div>
  238. <div class="expanded">
  239. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  240. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  241. <div id="manual-nav">
  242. <dl>
  243. <dd><a href="index.html#AllocsPerRun">func AllocsPerRun(runs int, f func()) (avg float64)</a></dd>
  244. <dd><a href="index.html#Coverage">func Coverage() float64</a></dd>
  245. <dd><a href="index.html#Main">func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample)</a></dd>
  246. <dd><a href="index.html#RegisterCover">func RegisterCover(c Cover)</a></dd>
  247. <dd><a href="index.html#RunBenchmarks">func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark)</a></dd>
  248. <dd><a href="index.html#RunExamples">func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool)</a></dd>
  249. <dd><a href="index.html#RunTests">func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool)</a></dd>
  250. <dd><a href="index.html#Short">func Short() bool</a></dd>
  251. <dd><a href="index.html#Verbose">func Verbose() bool</a></dd>
  252. <dd><a href="index.html#B">type B</a></dd>
  253. <dd>&nbsp; &nbsp; <a href="index.html#B.Error">func (c *B) Error(args ...interface{})</a></dd>
  254. <dd>&nbsp; &nbsp; <a href="index.html#B.Errorf">func (c *B) Errorf(format string, args ...interface{})</a></dd>
  255. <dd>&nbsp; &nbsp; <a href="index.html#B.Fail">func (c *B) Fail()</a></dd>
  256. <dd>&nbsp; &nbsp; <a href="index.html#B.FailNow">func (c *B) FailNow()</a></dd>
  257. <dd>&nbsp; &nbsp; <a href="index.html#B.Failed">func (c *B) Failed() bool</a></dd>
  258. <dd>&nbsp; &nbsp; <a href="index.html#B.Fatal">func (c *B) Fatal(args ...interface{})</a></dd>
  259. <dd>&nbsp; &nbsp; <a href="index.html#B.Fatalf">func (c *B) Fatalf(format string, args ...interface{})</a></dd>
  260. <dd>&nbsp; &nbsp; <a href="index.html#B.Log">func (c *B) Log(args ...interface{})</a></dd>
  261. <dd>&nbsp; &nbsp; <a href="index.html#B.Logf">func (c *B) Logf(format string, args ...interface{})</a></dd>
  262. <dd>&nbsp; &nbsp; <a href="index.html#B.ReportAllocs">func (b *B) ReportAllocs()</a></dd>
  263. <dd>&nbsp; &nbsp; <a href="index.html#B.ResetTimer">func (b *B) ResetTimer()</a></dd>
  264. <dd>&nbsp; &nbsp; <a href="index.html#B.RunParallel">func (b *B) RunParallel(body func(*PB))</a></dd>
  265. <dd>&nbsp; &nbsp; <a href="index.html#B.SetBytes">func (b *B) SetBytes(n int64)</a></dd>
  266. <dd>&nbsp; &nbsp; <a href="index.html#B.SetParallelism">func (b *B) SetParallelism(p int)</a></dd>
  267. <dd>&nbsp; &nbsp; <a href="index.html#B.Skip">func (c *B) Skip(args ...interface{})</a></dd>
  268. <dd>&nbsp; &nbsp; <a href="index.html#B.SkipNow">func (c *B) SkipNow()</a></dd>
  269. <dd>&nbsp; &nbsp; <a href="index.html#B.Skipf">func (c *B) Skipf(format string, args ...interface{})</a></dd>
  270. <dd>&nbsp; &nbsp; <a href="index.html#B.Skipped">func (c *B) Skipped() bool</a></dd>
  271. <dd>&nbsp; &nbsp; <a href="index.html#B.StartTimer">func (b *B) StartTimer()</a></dd>
  272. <dd>&nbsp; &nbsp; <a href="index.html#B.StopTimer">func (b *B) StopTimer()</a></dd>
  273. <dd><a href="index.html#BenchmarkResult">type BenchmarkResult</a></dd>
  274. <dd>&nbsp; &nbsp; <a href="index.html#Benchmark">func Benchmark(f func(b *B)) BenchmarkResult</a></dd>
  275. <dd>&nbsp; &nbsp; <a href="index.html#BenchmarkResult.AllocedBytesPerOp">func (r BenchmarkResult) AllocedBytesPerOp() int64</a></dd>
  276. <dd>&nbsp; &nbsp; <a href="index.html#BenchmarkResult.AllocsPerOp">func (r BenchmarkResult) AllocsPerOp() int64</a></dd>
  277. <dd>&nbsp; &nbsp; <a href="index.html#BenchmarkResult.MemString">func (r BenchmarkResult) MemString() string</a></dd>
  278. <dd>&nbsp; &nbsp; <a href="index.html#BenchmarkResult.NsPerOp">func (r BenchmarkResult) NsPerOp() int64</a></dd>
  279. <dd>&nbsp; &nbsp; <a href="index.html#BenchmarkResult.String">func (r BenchmarkResult) String() string</a></dd>
  280. <dd><a href="index.html#Cover">type Cover</a></dd>
  281. <dd><a href="index.html#CoverBlock">type CoverBlock</a></dd>
  282. <dd><a href="index.html#InternalBenchmark">type InternalBenchmark</a></dd>
  283. <dd><a href="index.html#InternalExample">type InternalExample</a></dd>
  284. <dd><a href="index.html#InternalTest">type InternalTest</a></dd>
  285. <dd><a href="index.html#M">type M</a></dd>
  286. <dd>&nbsp; &nbsp; <a href="index.html#MainStart">func MainStart(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M</a></dd>
  287. <dd>&nbsp; &nbsp; <a href="index.html#M.Run">func (m *M) Run() int</a></dd>
  288. <dd><a href="index.html#PB">type PB</a></dd>
  289. <dd>&nbsp; &nbsp; <a href="index.html#PB.Next">func (pb *PB) Next() bool</a></dd>
  290. <dd><a href="index.html#T">type T</a></dd>
  291. <dd>&nbsp; &nbsp; <a href="index.html#T.Error">func (c *T) Error(args ...interface{})</a></dd>
  292. <dd>&nbsp; &nbsp; <a href="index.html#T.Errorf">func (c *T) Errorf(format string, args ...interface{})</a></dd>
  293. <dd>&nbsp; &nbsp; <a href="index.html#T.Fail">func (c *T) Fail()</a></dd>
  294. <dd>&nbsp; &nbsp; <a href="index.html#T.FailNow">func (c *T) FailNow()</a></dd>
  295. <dd>&nbsp; &nbsp; <a href="index.html#T.Failed">func (c *T) Failed() bool</a></dd>
  296. <dd>&nbsp; &nbsp; <a href="index.html#T.Fatal">func (c *T) Fatal(args ...interface{})</a></dd>
  297. <dd>&nbsp; &nbsp; <a href="index.html#T.Fatalf">func (c *T) Fatalf(format string, args ...interface{})</a></dd>
  298. <dd>&nbsp; &nbsp; <a href="index.html#T.Log">func (c *T) Log(args ...interface{})</a></dd>
  299. <dd>&nbsp; &nbsp; <a href="index.html#T.Logf">func (c *T) Logf(format string, args ...interface{})</a></dd>
  300. <dd>&nbsp; &nbsp; <a href="index.html#T.Parallel">func (t *T) Parallel()</a></dd>
  301. <dd>&nbsp; &nbsp; <a href="index.html#T.Skip">func (c *T) Skip(args ...interface{})</a></dd>
  302. <dd>&nbsp; &nbsp; <a href="index.html#T.SkipNow">func (c *T) SkipNow()</a></dd>
  303. <dd>&nbsp; &nbsp; <a href="index.html#T.Skipf">func (c *T) Skipf(format string, args ...interface{})</a></dd>
  304. <dd>&nbsp; &nbsp; <a href="index.html#T.Skipped">func (c *T) Skipped() bool</a></dd>
  305. <dd><a href="index.html#TB">type TB</a></dd>
  306. </dl>
  307. </div><!-- #manual-nav -->
  308. <div id="pkg-examples">
  309. <h4>Examples</h4>
  310. <dl>
  311. <dd><a class="exampleLink" href="index.html#example_B_RunParallel">B.RunParallel</a></dd>
  312. </dl>
  313. </div>
  314. <h4>Package files</h4>
  315. <p>
  316. <span style="font-size:90%">
  317. <a href="http://localhost:6060/src/testing/allocs.go">allocs.go</a>
  318. <a href="http://localhost:6060/src/testing/benchmark.go">benchmark.go</a>
  319. <a href="http://localhost:6060/src/testing/cover.go">cover.go</a>
  320. <a href="http://localhost:6060/src/testing/example.go">example.go</a>
  321. <a href="http://localhost:6060/src/testing/testing.go">testing.go</a>
  322. </span>
  323. </p>
  324. </div><!-- .expanded -->
  325. </div><!-- #pkg-index -->
  326. <div id="pkg-callgraph" class="toggle" style="display: none">
  327. <div class="collapsed">
  328. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  329. </div> <!-- .expanded -->
  330. <div class="expanded">
  331. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  332. <p>
  333. In the call graph viewer below, each node
  334. is a function belonging to this package
  335. and its children are the functions it
  336. calls&mdash;perhaps dynamically.
  337. </p>
  338. <p>
  339. The root nodes are the entry points of the
  340. package: functions that may be called from
  341. outside the package.
  342. There may be non-exported or anonymous
  343. functions among them if they are called
  344. dynamically from another package.
  345. </p>
  346. <p>
  347. Click a node to visit that function's source code.
  348. From there you can visit its callers by
  349. clicking its declaring <code>func</code>
  350. token.
  351. </p>
  352. <p>
  353. Functions may be omitted if they were
  354. determined to be unreachable in the
  355. particular programs or tests that were
  356. analyzed.
  357. </p>
  358. <!-- Zero means show all package entry points. -->
  359. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  360. </div>
  361. </div> <!-- #pkg-callgraph -->
  362. <h2 id="AllocsPerRun">func <a href="http://localhost:6060/src/testing/allocs.go?s=671:722#L10">AllocsPerRun</a></h2>
  363. <pre>func AllocsPerRun(runs <a href="../builtin/index.html#int">int</a>, f func()) (avg <a href="../builtin/index.html#float64">float64</a>)</pre>
  364. <p>
  365. AllocsPerRun returns the average number of allocations during calls to f.
  366. Although the return value has type float64, it will always be an integral value.
  367. </p>
  368. <p>
  369. To compute the number of allocations, the function will first be run once as
  370. a warm-up. The average number of allocations over the specified number of
  371. runs will then be measured and returned.
  372. </p>
  373. <p>
  374. AllocsPerRun sets GOMAXPROCS to 1 during its measurement and will restore
  375. it before returning.
  376. </p>
  377. <h2 id="Coverage">func <a href="http://localhost:6060/src/testing/cover.go?s=1319:1342#L35">Coverage</a></h2>
  378. <pre>func Coverage() <a href="../builtin/index.html#float64">float64</a></pre>
  379. <p>
  380. Coverage reports the current code coverage as a fraction in the range [0, 1].
  381. If coverage is not enabled, Coverage returns 0.
  382. </p>
  383. <p>
  384. When running a large set of sequential test cases, checking Coverage after each one
  385. can be useful for identifying which test cases exercise new code paths.
  386. It is not a replacement for the reports generated by &#39;go test -cover&#39; and
  387. &#39;go tool cover&#39;.
  388. </p>
  389. <h2 id="Main">func <a href="http://localhost:6060/src/testing/testing.go?s=16680:16820#L469">Main</a></h2>
  390. <pre>func Main(matchString func(pat, str <a href="../builtin/index.html#string">string</a>) (<a href="../builtin/index.html#bool">bool</a>, <a href="../builtin/index.html#error">error</a>), tests []<a href="index.html#InternalTest">InternalTest</a>, benchmarks []<a href="index.html#InternalBenchmark">InternalBenchmark</a>, examples []<a href="index.html#InternalExample">InternalExample</a>)</pre>
  391. <p>
  392. An internal function but exported because it is cross-package; part of the implementation
  393. of the &#34;go test&#34; command.
  394. </p>
  395. <h2 id="RegisterCover">func <a href="http://localhost:6060/src/testing/cover.go?s=1782:1809#L54">RegisterCover</a></h2>
  396. <pre>func RegisterCover(c <a href="index.html#Cover">Cover</a>)</pre>
  397. <p>
  398. RegisterCover records the coverage data accumulators for the tests.
  399. NOTE: This function is internal to the testing infrastructure and may change.
  400. It is not covered (yet) by the Go 1 compatibility guidelines.
  401. </p>
  402. <h2 id="RunBenchmarks">func <a href="http://localhost:6060/src/testing/benchmark.go?s=8271:8370#L294">RunBenchmarks</a></h2>
  403. <pre>func RunBenchmarks(matchString func(pat, str <a href="../builtin/index.html#string">string</a>) (<a href="../builtin/index.html#bool">bool</a>, <a href="../builtin/index.html#error">error</a>), benchmarks []<a href="index.html#InternalBenchmark">InternalBenchmark</a>)</pre>
  404. <p>
  405. An internal function but exported because it is cross-package; part of the implementation
  406. of the &#34;go test&#34; command.
  407. </p>
  408. <h2 id="RunExamples">func <a href="http://localhost:6060/src/testing/example.go?s=314:417#L12">RunExamples</a></h2>
  409. <pre>func RunExamples(matchString func(pat, str <a href="../builtin/index.html#string">string</a>) (<a href="../builtin/index.html#bool">bool</a>, <a href="../builtin/index.html#error">error</a>), examples []<a href="index.html#InternalExample">InternalExample</a>) (ok <a href="../builtin/index.html#bool">bool</a>)</pre>
  410. <h2 id="RunTests">func <a href="http://localhost:6060/src/testing/testing.go?s=18462:18556#L533">RunTests</a></h2>
  411. <pre>func RunTests(matchString func(pat, str <a href="../builtin/index.html#string">string</a>) (<a href="../builtin/index.html#bool">bool</a>, <a href="../builtin/index.html#error">error</a>), tests []<a href="index.html#InternalTest">InternalTest</a>) (ok <a href="../builtin/index.html#bool">bool</a>)</pre>
  412. <h2 id="Short">func <a href="http://localhost:6060/src/testing/testing.go?s=8442:8459#L201">Short</a></h2>
  413. <pre>func Short() <a href="../builtin/index.html#bool">bool</a></pre>
  414. <p>
  415. Short reports whether the -test.short flag is set.
  416. </p>
  417. <h2 id="Verbose">func <a href="http://localhost:6060/src/testing/testing.go?s=8532:8551#L206">Verbose</a></h2>
  418. <pre>func Verbose() <a href="../builtin/index.html#bool">bool</a></pre>
  419. <p>
  420. Verbose reports whether the -test.v flag is set.
  421. </p>
  422. <h2 id="B">type <a href="http://localhost:6060/src/testing/benchmark.go?s=1642:2246#L37">B</a></h2>
  423. <pre>type B struct {
  424. N <a href="../builtin/index.html#int">int</a>
  425. <span class="comment">// contains filtered or unexported fields</span>
  426. }</pre>
  427. <p>
  428. B is a type passed to Benchmark functions to manage benchmark
  429. timing and to specify the number of iterations to run.
  430. </p>
  431. <p>
  432. A benchmark ends when its Benchmark function returns or calls any of the methods
  433. FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods must be called
  434. only from the goroutine running the Benchmark function.
  435. The other reporting methods, such as the variations of Log and Error,
  436. may be called simultaneously from multiple goroutines.
  437. </p>
  438. <p>
  439. Like in tests, benchmark logs are accumulated during execution
  440. and dumped to standard error when done. Unlike in tests, benchmark logs
  441. are always printed, so as not to hide output whose existence may be
  442. affecting benchmark results.
  443. </p>
  444. <h3 id="B.Error">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=13685:13728#L359">Error</a></h3>
  445. <pre>func (c *<a href="index.html#B">B</a>) Error(args ...interface{})</pre>
  446. <p>
  447. Error is equivalent to Log followed by Fail.
  448. </p>
  449. <h3 id="B.Errorf">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=13824:13883#L365">Errorf</a></h3>
  450. <pre>func (c *<a href="index.html#B">B</a>) Errorf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  451. <p>
  452. Errorf is equivalent to Logf followed by Fail.
  453. </p>
  454. <h3 id="B.Fail">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=11125:11148#L294">Fail</a></h3>
  455. <pre>func (c *<a href="index.html#B">B</a>) Fail()</pre>
  456. <p>
  457. Fail marks the function as having failed but continues execution.
  458. </p>
  459. <h3 id="B.FailNow">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=11674:11700#L313">FailNow</a></h3>
  460. <pre>func (c *<a href="index.html#B">B</a>) FailNow()</pre>
  461. <p>
  462. FailNow marks the function as having failed and stops its execution.
  463. Execution will continue at the next test or benchmark.
  464. FailNow must be called from the goroutine running the
  465. test or benchmark function, not from other goroutines
  466. created during the test. Calling FailNow does not stop
  467. those other goroutines.
  468. </p>
  469. <h3 id="B.Failed">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=11256:11286#L301">Failed</a></h3>
  470. <pre>func (c *<a href="index.html#B">B</a>) Failed() <a href="../builtin/index.html#bool">bool</a></pre>
  471. <p>
  472. Failed reports whether the function has failed.
  473. </p>
  474. <h3 id="B.Fatal">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=13987:14030#L371">Fatal</a></h3>
  475. <pre>func (c *<a href="index.html#B">B</a>) Fatal(args ...interface{})</pre>
  476. <p>
  477. Fatal is equivalent to Log followed by FailNow.
  478. </p>
  479. <h3 id="B.Fatalf">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=14132:14191#L377">Fatalf</a></h3>
  480. <pre>func (c *<a href="index.html#B">B</a>) Fatalf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  481. <p>
  482. Fatalf is equivalent to Logf followed by FailNow.
  483. </p>
  484. <h3 id="B.Log">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=13139:13180#L350">Log</a></h3>
  485. <pre>func (c *<a href="index.html#B">B</a>) Log(args ...interface{})</pre>
  486. <p>
  487. Log formats its arguments using default formatting, analogous to Println,
  488. and records the text in the error log. For tests, the text will be printed only if
  489. the test fails or the -test.v flag is set. For benchmarks, the text is always
  490. printed to avoid having performance depend on the value of the -test.v flag.
  491. </p>
  492. <h3 id="B.Logf">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=13538:13595#L356">Logf</a></h3>
  493. <pre>func (c *<a href="index.html#B">B</a>) Logf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  494. <p>
  495. Logf formats its arguments according to the format, analogous to Printf,
  496. and records the text in the error log. For tests, the text will be printed only if
  497. the test fails or the -test.v flag is set. For benchmarks, the text is always
  498. printed to avoid having performance depend on the value of the -test.v flag.
  499. </p>
  500. <h3 id="B.ReportAllocs">func (*B) <a href="http://localhost:6060/src/testing/benchmark.go?s=3733:3759#L103">ReportAllocs</a></h3>
  501. <pre>func (b *<a href="index.html#B">B</a>) ReportAllocs()</pre>
  502. <p>
  503. ReportAllocs enables malloc statistics for this benchmark.
  504. It is equivalent to setting -test.benchmem, but it only affects the
  505. benchmark function that calls ReportAllocs.
  506. </p>
  507. <h3 id="B.ResetTimer">func (*B) <a href="http://localhost:6060/src/testing/benchmark.go?s=3142:3166#L84">ResetTimer</a></h3>
  508. <pre>func (b *<a href="index.html#B">B</a>) ResetTimer()</pre>
  509. <p>
  510. ResetTimer zeros the elapsed benchmark time and memory allocation counters.
  511. It does not affect whether the timer is running.
  512. </p>
  513. <h3 id="B.RunParallel">func (*B) <a href="http://localhost:6060/src/testing/benchmark.go?s=12016:12055#L410">RunParallel</a></h3>
  514. <pre>func (b *<a href="index.html#B">B</a>) RunParallel(body func(*<a href="index.html#PB">PB</a>))</pre>
  515. <p>
  516. RunParallel runs a benchmark in parallel.
  517. It creates multiple goroutines and distributes b.N iterations among them.
  518. The number of goroutines defaults to GOMAXPROCS. To increase parallelism for
  519. non-CPU-bound benchmarks, call SetParallelism before RunParallel.
  520. RunParallel is usually used with the go test -cpu flag.
  521. </p>
  522. <p>
  523. The body function will be run in each goroutine. It should set up any
  524. goroutine-local state and then iterate until pb.Next returns false.
  525. It should not use the StartTimer, StopTimer, or ResetTimer functions,
  526. because they have global effect.
  527. </p>
  528. <div id="example_B_RunParallel" class="toggle">
  529. <div class="collapsed">
  530. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  531. </div>
  532. <div class="expanded">
  533. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  534. <p>Code:</p>
  535. <pre class="code">
  536. <span class="comment">// Parallel benchmark for text/template.Template.Execute on a single object.</span>
  537. testing.Benchmark(func(b *testing.B) {
  538. templ := template.Must(template.New(&#34;test&#34;).Parse(&#34;Hello, {{.}}!&#34;))
  539. <span class="comment">// RunParallel will create GOMAXPROCS goroutines</span>
  540. <span class="comment">// and distribute work among them.</span>
  541. b.RunParallel(func(pb *testing.PB) {
  542. <span class="comment">// Each goroutine has its own bytes.Buffer.</span>
  543. var buf bytes.Buffer
  544. for pb.Next() {
  545. <span class="comment">// The loop body is executed b.N times total across all goroutines.</span>
  546. buf.Reset()
  547. templ.Execute(&amp;buf, &#34;World&#34;)
  548. }
  549. })
  550. })
  551. </pre>
  552. </div>
  553. </div>
  554. <h3 id="B.SetBytes">func (*B) <a href="http://localhost:6060/src/testing/benchmark.go?s=3506:3535#L98">SetBytes</a></h3>
  555. <pre>func (b *<a href="index.html#B">B</a>) SetBytes(n <a href="../builtin/index.html#int64">int64</a>)</pre>
  556. <p>
  557. SetBytes records the number of bytes processed in a single operation.
  558. If this is called, the benchmark will report ns/op and MB/s.
  559. </p>
  560. <h3 id="B.SetParallelism">func (*B) <a href="http://localhost:6060/src/testing/benchmark.go?s=13165:13198#L451">SetParallelism</a></h3>
  561. <pre>func (b *<a href="index.html#B">B</a>) SetParallelism(p <a href="../builtin/index.html#int">int</a>)</pre>
  562. <p>
  563. SetParallelism sets the number of goroutines used by RunParallel to p*GOMAXPROCS.
  564. There is usually no need to call SetParallelism for CPU-bound benchmarks.
  565. If p is less than 1, this call will have no effect.
  566. </p>
  567. <h3 id="B.Skip">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=14297:14339#L383">Skip</a></h3>
  568. <pre>func (c *<a href="index.html#B">B</a>) Skip(args ...interface{})</pre>
  569. <p>
  570. Skip is equivalent to Log followed by SkipNow.
  571. </p>
  572. <h3 id="B.SkipNow">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=14878:14904#L399">SkipNow</a></h3>
  573. <pre>func (c *<a href="index.html#B">B</a>) SkipNow()</pre>
  574. <p>
  575. SkipNow marks the test as having been skipped and stops its execution.
  576. Execution will continue at the next test or benchmark. See also FailNow.
  577. SkipNow must be called from the goroutine running the test, not from
  578. other goroutines created during the test. Calling SkipNow does not stop
  579. those other goroutines.
  580. </p>
  581. <h3 id="B.Skipf">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=14440:14498#L389">Skipf</a></h3>
  582. <pre>func (c *<a href="index.html#B">B</a>) Skipf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  583. <p>
  584. Skipf is equivalent to Logf followed by SkipNow.
  585. </p>
  586. <h3 id="B.Skipped">func (*B) <a href="http://localhost:6060/src/testing/testing.go?s=15087:15118#L412">Skipped</a></h3>
  587. <pre>func (c *<a href="index.html#B">B</a>) Skipped() <a href="../builtin/index.html#bool">bool</a></pre>
  588. <p>
  589. Skipped reports whether the test was skipped.
  590. </p>
  591. <h3 id="B.StartTimer">func (*B) <a href="http://localhost:6060/src/testing/benchmark.go?s=2421:2445#L59">StartTimer</a></h3>
  592. <pre>func (b *<a href="index.html#B">B</a>) StartTimer()</pre>
  593. <p>
  594. StartTimer starts timing a test. This function is called automatically
  595. before a benchmark starts, but it can also used to resume timing after
  596. a call to StopTimer.
  597. </p>
  598. <h3 id="B.StopTimer">func (*B) <a href="http://localhost:6060/src/testing/benchmark.go?s=2768:2791#L72">StopTimer</a></h3>
  599. <pre>func (b *<a href="index.html#B">B</a>) StopTimer()</pre>
  600. <p>
  601. StopTimer stops timing a test. This can be used to pause the timer
  602. while performing complex initialization that you don&#39;t
  603. want to measure.
  604. </p>
  605. <h2 id="BenchmarkResult">type <a href="http://localhost:6060/src/testing/benchmark.go?s=6395:6725#L223">BenchmarkResult</a></h2>
  606. <pre>type BenchmarkResult struct {
  607. N <a href="../builtin/index.html#int">int</a> <span class="comment">// The number of iterations.</span>
  608. T <a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a> <span class="comment">// The total time taken.</span>
  609. Bytes <a href="../builtin/index.html#int64">int64</a> <span class="comment">// Bytes processed in one iteration.</span>
  610. MemAllocs <a href="../builtin/index.html#uint64">uint64</a> <span class="comment">// The total number of memory allocations.</span>
  611. MemBytes <a href="../builtin/index.html#uint64">uint64</a> <span class="comment">// The total number of bytes allocated.</span>
  612. }</pre>
  613. <p>
  614. The results of a benchmark run.
  615. </p>
  616. <h3 id="Benchmark">func <a href="http://localhost:6060/src/testing/benchmark.go?s=13363:13407#L459">Benchmark</a></h3>
  617. <pre>func Benchmark(f func(b *<a href="index.html#B">B</a>)) <a href="index.html#BenchmarkResult">BenchmarkResult</a></pre>
  618. <p>
  619. Benchmark benchmarks a single function. Useful for creating
  620. custom benchmarks that do not use the &#34;go test&#34; command.
  621. </p>
  622. <h3 id="BenchmarkResult.AllocedBytesPerOp">func (BenchmarkResult) <a href="http://localhost:6060/src/testing/benchmark.go?s=7130:7180#L252">AllocedBytesPerOp</a></h3>
  623. <pre>func (r <a href="index.html#BenchmarkResult">BenchmarkResult</a>) AllocedBytesPerOp() <a href="../builtin/index.html#int64">int64</a></pre>
  624. <h3 id="BenchmarkResult.AllocsPerOp">func (BenchmarkResult) <a href="http://localhost:6060/src/testing/benchmark.go?s=7011:7055#L245">AllocsPerOp</a></h3>
  625. <pre>func (r <a href="index.html#BenchmarkResult">BenchmarkResult</a>) AllocsPerOp() <a href="../builtin/index.html#int64">int64</a></pre>
  626. <h3 id="BenchmarkResult.MemString">func (BenchmarkResult) <a href="http://localhost:6060/src/testing/benchmark.go?s=7820:7863#L279">MemString</a></h3>
  627. <pre>func (r <a href="index.html#BenchmarkResult">BenchmarkResult</a>) MemString() <a href="../builtin/index.html#string">string</a></pre>
  628. <h3 id="BenchmarkResult.NsPerOp">func (BenchmarkResult) <a href="http://localhost:6060/src/testing/benchmark.go?s=6727:6767#L231">NsPerOp</a></h3>
  629. <pre>func (r <a href="index.html#BenchmarkResult">BenchmarkResult</a>) NsPerOp() <a href="../builtin/index.html#int64">int64</a></pre>
  630. <h3 id="BenchmarkResult.String">func (BenchmarkResult) <a href="http://localhost:6060/src/testing/benchmark.go?s=7254:7294#L259">String</a></h3>
  631. <pre>func (r <a href="index.html#BenchmarkResult">BenchmarkResult</a>) String() <a href="../builtin/index.html#string">string</a></pre>
  632. <h2 id="Cover">type <a href="http://localhost:6060/src/testing/cover.go?s=776:923#L21">Cover</a></h2>
  633. <pre>type Cover struct {
  634. Mode <a href="../builtin/index.html#string">string</a>
  635. Counters map[<a href="../builtin/index.html#string">string</a>][]<a href="../builtin/index.html#uint32">uint32</a>
  636. Blocks map[<a href="../builtin/index.html#string">string</a>][]<a href="index.html#CoverBlock">CoverBlock</a>
  637. CoveredPackages <a href="../builtin/index.html#string">string</a>
  638. }</pre>
  639. <p>
  640. Cover records information about test coverage checking.
  641. NOTE: This struct is internal to the testing infrastructure and may change.
  642. It is not covered (yet) by the Go 1 compatibility guidelines.
  643. </p>
  644. <h2 id="CoverBlock">type <a href="http://localhost:6060/src/testing/cover.go?s=458:554#L8">CoverBlock</a></h2>
  645. <pre>type CoverBlock struct {
  646. Line0 <a href="../builtin/index.html#uint32">uint32</a>
  647. Col0 <a href="../builtin/index.html#uint16">uint16</a>
  648. Line1 <a href="../builtin/index.html#uint32">uint32</a>
  649. Col1 <a href="../builtin/index.html#uint16">uint16</a>
  650. Stmts <a href="../builtin/index.html#uint16">uint16</a>
  651. }</pre>
  652. <p>
  653. CoverBlock records the coverage data for a single basic block.
  654. NOTE: This struct is internal to the testing infrastructure and may change.
  655. It is not covered (yet) by the Go 1 compatibility guidelines.
  656. </p>
  657. <h2 id="InternalBenchmark">type <a href="http://localhost:6060/src/testing/benchmark.go?s=849:912#L19">InternalBenchmark</a></h2>
  658. <pre>type InternalBenchmark struct {
  659. Name <a href="../builtin/index.html#string">string</a>
  660. F func(b *<a href="index.html#B">B</a>)
  661. }</pre>
  662. <p>
  663. An internal type but exported because it is cross-package; part of the implementation
  664. of the &#34;go test&#34; command.
  665. </p>
  666. <h2 id="InternalExample">type <a href="http://localhost:6060/src/testing/example.go?s=236:312#L6">InternalExample</a></h2>
  667. <pre>type InternalExample struct {
  668. Name <a href="../builtin/index.html#string">string</a>
  669. F func()
  670. Output <a href="../builtin/index.html#string">string</a>
  671. }</pre>
  672. <h2 id="InternalTest">type <a href="http://localhost:6060/src/testing/testing.go?s=15861:15917#L437">InternalTest</a></h2>
  673. <pre>type InternalTest struct {
  674. Name <a href="../builtin/index.html#string">string</a>
  675. F func(*<a href="index.html#T">T</a>)
  676. }</pre>
  677. <p>
  678. An internal type but exported because it is cross-package; part of the implementation
  679. of the &#34;go test&#34; command.
  680. </p>
  681. <h2 id="M">type <a href="http://localhost:6060/src/testing/testing.go?s=16964:17122#L474">M</a></h2>
  682. <pre>type M struct {
  683. <span class="comment">// contains filtered or unexported fields</span>
  684. }</pre>
  685. <p>
  686. M is a type passed to a TestMain function to run the actual tests.
  687. </p>
  688. <h3 id="MainStart">func <a href="http://localhost:6060/src/testing/testing.go?s=17335:17483#L484">MainStart</a></h3>
  689. <pre>func MainStart(matchString func(pat, str <a href="../builtin/index.html#string">string</a>) (<a href="../builtin/index.html#bool">bool</a>, <a href="../builtin/index.html#error">error</a>), tests []<a href="index.html#InternalTest">InternalTest</a>, benchmarks []<a href="index.html#InternalBenchmark">InternalBenchmark</a>, examples []<a href="index.html#InternalExample">InternalExample</a>) *<a href="index.html#M">M</a></pre>
  690. <p>
  691. MainStart is meant for use by tests generated by &#39;go test&#39;.
  692. It is not meant to be called directly and is not subject to the Go 1 compatibility document.
  693. It may change signature from release to release.
  694. </p>
  695. <h3 id="M.Run">func (*M) <a href="http://localhost:6060/src/testing/testing.go?s=17673:17694#L494">Run</a></h3>
  696. <pre>func (m *<a href="index.html#M">M</a>) Run() <a href="../builtin/index.html#int">int</a></pre>
  697. <p>
  698. Run runs the tests. It returns an exit code to pass to os.Exit.
  699. </p>
  700. <h2 id="PB">type <a href="http://localhost:6060/src/testing/benchmark.go?s=10819:11101#L377">PB</a></h2>
  701. <pre>type PB struct {
  702. <span class="comment">// contains filtered or unexported fields</span>
  703. }</pre>
  704. <p>
  705. A PB is used by RunParallel for running parallel benchmarks.
  706. </p>
  707. <h3 id="PB.Next">func (*PB) <a href="http://localhost:6060/src/testing/benchmark.go?s=11165:11190#L385">Next</a></h3>
  708. <pre>func (pb *<a href="index.html#PB">PB</a>) Next() <a href="../builtin/index.html#bool">bool</a></pre>
  709. <p>
  710. Next reports whether there are more iterations to execute.
  711. </p>
  712. <h2 id="T">type <a href="http://localhost:6060/src/testing/testing.go?s=10877:11023#L284">T</a></h2>
  713. <pre>type T struct {
  714. <span class="comment">// contains filtered or unexported fields</span>
  715. }</pre>
  716. <p>
  717. T is a type passed to Test functions to manage test state and support formatted test logs.
  718. Logs are accumulated during execution and dumped to standard error when done.
  719. </p>
  720. <p>
  721. A test ends when its Test function returns or calls any of the methods
  722. FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods, as well as
  723. the Parallel method, must be called only from the goroutine running the
  724. Test function.
  725. </p>
  726. <p>
  727. The other reporting methods, such as the variations of Log and Error,
  728. may be called simultaneously from multiple goroutines.
  729. </p>
  730. <h3 id="T.Error">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=13685:13728#L359">Error</a></h3>
  731. <pre>func (c *<a href="index.html#T">T</a>) Error(args ...interface{})</pre>
  732. <p>
  733. Error is equivalent to Log followed by Fail.
  734. </p>
  735. <h3 id="T.Errorf">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=13824:13883#L365">Errorf</a></h3>
  736. <pre>func (c *<a href="index.html#T">T</a>) Errorf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  737. <p>
  738. Errorf is equivalent to Logf followed by Fail.
  739. </p>
  740. <h3 id="T.Fail">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=11125:11148#L294">Fail</a></h3>
  741. <pre>func (c *<a href="index.html#T">T</a>) Fail()</pre>
  742. <p>
  743. Fail marks the function as having failed but continues execution.
  744. </p>
  745. <h3 id="T.FailNow">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=11674:11700#L313">FailNow</a></h3>
  746. <pre>func (c *<a href="index.html#T">T</a>) FailNow()</pre>
  747. <p>
  748. FailNow marks the function as having failed and stops its execution.
  749. Execution will continue at the next test or benchmark.
  750. FailNow must be called from the goroutine running the
  751. test or benchmark function, not from other goroutines
  752. created during the test. Calling FailNow does not stop
  753. those other goroutines.
  754. </p>
  755. <h3 id="T.Failed">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=11256:11286#L301">Failed</a></h3>
  756. <pre>func (c *<a href="index.html#T">T</a>) Failed() <a href="../builtin/index.html#bool">bool</a></pre>
  757. <p>
  758. Failed reports whether the function has failed.
  759. </p>
  760. <h3 id="T.Fatal">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=13987:14030#L371">Fatal</a></h3>
  761. <pre>func (c *<a href="index.html#T">T</a>) Fatal(args ...interface{})</pre>
  762. <p>
  763. Fatal is equivalent to Log followed by FailNow.
  764. </p>
  765. <h3 id="T.Fatalf">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=14132:14191#L377">Fatalf</a></h3>
  766. <pre>func (c *<a href="index.html#T">T</a>) Fatalf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  767. <p>
  768. Fatalf is equivalent to Logf followed by FailNow.
  769. </p>
  770. <h3 id="T.Log">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=13139:13180#L350">Log</a></h3>
  771. <pre>func (c *<a href="index.html#T">T</a>) Log(args ...interface{})</pre>
  772. <p>
  773. Log formats its arguments using default formatting, analogous to Println,
  774. and records the text in the error log. For tests, the text will be printed only if
  775. the test fails or the -test.v flag is set. For benchmarks, the text is always
  776. printed to avoid having performance depend on the value of the -test.v flag.
  777. </p>
  778. <h3 id="T.Logf">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=13538:13595#L356">Logf</a></h3>
  779. <pre>func (c *<a href="index.html#T">T</a>) Logf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  780. <p>
  781. Logf formats its arguments according to the format, analogous to Printf,
  782. and records the text in the error log. For tests, the text will be printed only if
  783. the test fails or the -test.v flag is set. For benchmarks, the text is always
  784. printed to avoid having performance depend on the value of the -test.v flag.
  785. </p>
  786. <h3 id="T.Parallel">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=15284:15306#L420">Parallel</a></h3>
  787. <pre>func (t *<a href="index.html#T">T</a>) Parallel()</pre>
  788. <p>
  789. Parallel signals that this test is to be run in parallel with (and only with)
  790. other parallel tests.
  791. </p>
  792. <h3 id="T.Skip">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=14297:14339#L383">Skip</a></h3>
  793. <pre>func (c *<a href="index.html#T">T</a>) Skip(args ...interface{})</pre>
  794. <p>
  795. Skip is equivalent to Log followed by SkipNow.
  796. </p>
  797. <h3 id="T.SkipNow">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=14878:14904#L399">SkipNow</a></h3>
  798. <pre>func (c *<a href="index.html#T">T</a>) SkipNow()</pre>
  799. <p>
  800. SkipNow marks the test as having been skipped and stops its execution.
  801. Execution will continue at the next test or benchmark. See also FailNow.
  802. SkipNow must be called from the goroutine running the test, not from
  803. other goroutines created during the test. Calling SkipNow does not stop
  804. those other goroutines.
  805. </p>
  806. <h3 id="T.Skipf">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=14440:14498#L389">Skipf</a></h3>
  807. <pre>func (c *<a href="index.html#T">T</a>) Skipf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})</pre>
  808. <p>
  809. Skipf is equivalent to Logf followed by SkipNow.
  810. </p>
  811. <h3 id="T.Skipped">func (*T) <a href="http://localhost:6060/src/testing/testing.go?s=15087:15118#L412">Skipped</a></h3>
  812. <pre>func (c *<a href="index.html#T">T</a>) Skipped() <a href="../builtin/index.html#bool">bool</a></pre>
  813. <p>
  814. Skipped reports whether the test was skipped.
  815. </p>
  816. <h2 id="TB">type <a href="http://localhost:6060/src/testing/testing.go?s=9759:10275#L250">TB</a></h2>
  817. <pre>type TB interface {
  818. Error(args ...interface{})
  819. Errorf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})
  820. Fail()
  821. FailNow()
  822. Failed() <a href="../builtin/index.html#bool">bool</a>
  823. Fatal(args ...interface{})
  824. Fatalf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})
  825. Log(args ...interface{})
  826. Logf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})
  827. Skip(args ...interface{})
  828. SkipNow()
  829. Skipf(format <a href="../builtin/index.html#string">string</a>, args ...interface{})
  830. Skipped() <a href="../builtin/index.html#bool">bool</a>
  831. <span class="comment">// contains filtered or unexported methods</span>
  832. }</pre>
  833. <p>
  834. TB is the interface common to T and B.
  835. </p>
  836. <h2 id="pkg-subdirectories">Subdirectories</h2>
  837. <div class="pkg-dir">
  838. <table>
  839. <tr>
  840. <th class="pkg-name">Name</th>
  841. <th class="pkg-synopsis">Synopsis</th>
  842. </tr>
  843. <tr>
  844. <td colspan="2"><a href="http://localhost:6060/pkg/">..</a></td>
  845. </tr>
  846. <tr>
  847. <td class="pkg-name" style="padding-left: 0px;">
  848. <a href="iotest/index.html">iotest</a>
  849. </td>
  850. <td class="pkg-synopsis">
  851. Package iotest implements Readers and Writers useful mainly for testing.
  852. </td>
  853. </tr>
  854. <tr>
  855. <td class="pkg-name" style="padding-left: 0px;">
  856. <a href="quick/index.html">quick</a>
  857. </td>
  858. <td class="pkg-synopsis">
  859. Package quick implements utility functions to help with black box testing.
  860. </td>
  861. </tr>
  862. </table>
  863. </div>
  864. <div id="footer">
  865. Build version go1.6.<br>
  866. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  867. the content of this page is licensed under the
  868. Creative Commons Attribution 3.0 License,
  869. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  870. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  871. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  872. </div>
  873. </div><!-- .container -->
  874. </div><!-- #page -->
  875. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  876. <script type="text/javascript" src="../../lib/godoc/jquery.js"></script>
  877. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.js"></script>
  878. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.edit.js"></script>
  879. <script type="text/javascript" src="../../lib/godoc/godocs.js"></script>
  880. </body>
  881. </html>