Go: Unit Testing

  1. The test file name must  _test.go  end;
  2. Test function name must start with Test, General: Test + function name to be tested (first letter should be capitalized) ;
  3. func TestXx (t * testing.T) {}, t test parameters for reporting failures and additional log information;
  4. If no go test command parameter specifies that the packet will use the default packet corresponding to the current directory;
the Test Go 
Go the Test package name 
go test -v // -v parameter can be used to print the name and function of each test run time 
go test -v -run = "Add | Mul" // parameter -run corresponds to a regular expression, only test function names are correctly matched its function will be go test test test command run 
go test -v -run Add // as long as the test function name contains Add, will perform the test 
go test -v xx_test.go xx.go / / test a single document, the original document must be brought to be tested

 

Guess you like

Origin www.cnblogs.com/believepd/p/10964301.html