Golang Unit Test

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

1. Golang unit test for File name and method name requirements

    • The file name must be xx_test.go named
    • Method must be the Test[^a-z] beginning
    • Method parameters must bet *testing.T

2. Go Test parameter interpretation

  
go testIt is a test tool that comes with the Go language, which contains two classes, unit tests , and performance tests . go help testyou can see the instructions for using go test:

  • Format

    go test [-c] [-i] [build flags] [packages] [flags for test binary]
  • Parameters

    -C : compile go test to be an executable binary, but do not run the tests. -I : installs the package that the test pack relies on, but does not run the test. About build flags, call go help build, these are the parameters that need to be used during the compilation run, generally set to empty about packages, call go to the packages, these are about the management of the package, generally set to null about the flags for test Binary, call go help Testflag, these are the parameters that are often used during go test-TEST.V : whether to output all of the unit test cases (whether successful or unsuccessful), the default is not added, so only the failed unit test cases are output. -test.run pattern: which unit test cases run only-test.bench Patten: run only those performance test cases-Test.benchmem : whether to output memory when performance tests are in progress-test.benchtime T : Time of performance test run, default is 1s-test.cpuprofile cpu.out : whether to output CPU profiling files-test.memprofile mem.out : whether to output memory profiling files-test.blockprofile block.out : whether to output the performance analysis file for internal goroutine blocking-test.memprofilerate n : Memory Performance Analysis when there is an allocation of how many times before the issue of records. This parameter sets the memory allocation interval for the dot, which is the memory size represented by a sample in profile. The default is set  to * 1024x768 . If you set it to 1, each allocated block of memory will have a dot in the profile, so there will be a lot of sample generated for the profile. If you set it to 0, you are not doing a dot. You can turn off memory reclamation by setting memprofilerate=1 and Gogc=off, and observe the allocation of each block of memory. -test.blockprofilerate N: basic ibid., which controls the number of nanoseconds to be goroutine when blocking. The default is not set to the equivalent of-test.blockprofilerate=1, each nanosecond to record a bit-test.parallel n : number of program parallel CPUs for performance testing, default equals Gomaxprocs. -test.timeout T : throws panic if the test case runs longer than T-test.cpu 1,2,4 : which CPU The program is running on, the binary 1 is used to represent the location, And Nginx's nginx_worker_cpu_affinity is a truth-Test.short : Shorten the run time of those test cases that run longer

Finish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.