Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit c8c284f

Browse files
committed
Add testing page
1 parent f680b79 commit c8c284f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pages/testing.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Testing
3+
parent: 1465
4+
template: page-tut.php
5+
order: 24
6+
---
7+
8+
# Testing
9+
10+
The [Go testing package](https://golang.org/pkg/testing/) supports creating unit test in go. Your test code is written in plain go, there is not a new assert language or syntax to learn. You write go code, and then Fail or Error out to signal the test did not pass.
11+
12+
To write a new test created a test file, ending in `_test.go` which includes functions with the following signature: `func TestXxx(*testing.T)`
13+
14+
Note: The function name must start with `Test` and include a capitalized second part which is used to identify the test routing.
15+
16+
For example, if you want to test an `Add` function in your project:
17+
18+
Create `add_test.go`:
19+
20+
```go
21+
package main
22+
23+
import "testing"
24+
25+
func TestAdd(t *testing.T) {
26+
sum := Add(1, 1)
27+
if sum != 2 {
28+
t.Errorf("Expected %d => Received %d", 2, sum)
29+
}
30+
}
31+
```
32+
33+
Run test using: `go test`
34+

0 commit comments

Comments
 (0)