Go Language base Unit Test example

Source: Internet
Author: User

This should be familiar with the principle, to be able to write.

But now .....

Note that there is no main function to _test.go the end of the command go test-v

Package Mainimport ("Testing" "Net/http") const Checkmark = "ok!" Const BALLOTX = "error!" Func testdownload (t *testing. T) {URL: = "http://localhost:8000/test.html" StatusCode: = 200t. Log ("Given the need to test downloading content.") {T.LOGF ("\twhen checking \"%s\ "for status code \"%d\ "", URL, statusCode) {resp, err: = http. Get (URL) if err! = Nil {t.fatal ("\tshould is able to make the get call.", Ballotx, Err)}t.log ("\t\tshould is able to make T He Get call. ", checkmark) Defer resp. Body.close () If Resp. StatusCode = = StatusCode {T.LOGF ("\t\tshould receive a \"%d\ "status,%v", StatusCode, Checkmark)} else {T.errorf ("\t\tsho Uld receive a \ "%d\" status. %v%v ", StatusCode, Ballotx, resp. StatusCode)}}}}

  

Go Language base Unit Test example

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.