In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to write the test module in go language". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to write the test module in go language.
How to write test module 1. 1 using native testing module in go language. First of all, as to how to name the test module, according to official regulations, when writing a test package, you should write the test package with the source file name followed by the end of _ test.go. If the original file name is `main.go`, the test package should be written as `main.go` according to the regulations. Of course, if your two files are in the same folder, there is no problem, and just make sure it ends with _ test. two。 Examples of test packages
Source file main.go
Package mainimport "fmt" func gotest (num int) {total: = 0 for n: = 0; n < num; n + + {total + = n fmt.Println (total)}} func main () {gotest (100)}
Test file main_test.go
Package mainimport ("testing") func TestYou (t * testing.T) {/ / Note that the TestYou here must adopt the hump nomenclature gotest (100)} 3. Finally, you can execute go test in the terminal, or you can specify the file go test main.go main_test.go or test go-v4. How to test the code in the package sequentially? There is no order for code execution in the test package, but if you want the code tests to be in order, for example, when doing web development, you should first connect to the database. So the function t.run () is used at this time.
Main function main.go
Package mainimport "fmt" func gotest (num int) {total: = 0 for n: = 0; n < num; n + + {total + = n} fmt.Println (total)} func main () {gotest (100)}
Test function main_test.go
Package mainimport ("testing") func testYou1 (t * testing.T) {gotest (100)} func testYou2 (t * testing.T) {gotest (100)} func TestAll (t * testing.T) {t.Run ("testYou1", testYou1) t.Run ("testYou2", testYou2)} in addition, the TestMain () function will be the first to thank you for your reading. This is the content of "how to write a test module in go language". After the study of this article, I believe that you have a deeper understanding of how to write the test module in go language, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.