This is a creation in Article, where the information may have evolved or changed. F:./SRC
└─hello
Hello.go
Hello_test.go
Hello.go
=========
Package Hello
Import"FMT"
FuncAdd (A, b int) (result int) {
returnA + b
}
FuncMain (){
FMT. Println ("Hello, World. ") Hello, world! ")
C: = ADD (1, 2)
FMT. Println ("c=", c)
}
Hello_test.go
Package Hello
Import(
"FMT"
"Testing"
"Time"
)
FuncTestAdd1 (t *testing. T) {
FMT. Println ("Add Test")
r: = ADD (1, 2)
ifr! = 2 {// this should be 3, deliberately changed to 2 test error scenario
T.errorf ("Add (1, 2) failed. Got%d, expected 3. ", R)
}
FMT. PRINTLN ("Other test Tests")//Add additional tests
}
FuncBenchmarkAdd1 (b *testing. B) {
FMT. Println ("Perform the Add Performance test")
b.stoptimer () //Pause Timer
time . Sleep (3) //A lengthy preparatory work, such as reading a file
B.starttimer ()//Turn on the timer, before the preparation time is not counted in the total time spent
For i: = 0; i < B.N; i++ {
Add (1, 2)
} Fmt. PRINTLN ("Other test Tests")//Add additional tests}
You can compile and run directly from the menu directly under Liteide.
The following is the form of the command line
C:/go/bin/go.exe test [F:/golang/test/src/hello]
C:/go/bin/go.exe test-test.bench=.* [F:/golang/test/src/hello]