官术网_书友最值得收藏!

Testing in Go

Testing is an important part of programming, whether it is in Go or in any other language. Go has a straightforward approach to writing tests, and in this section, we will look at some important tools to help with testing.

There are certain rules and conventions we need to follow to test our code. They can be listed as follows:

  • Source files and associated test files are placed in the same package/folder
  • The name of the test file for any given source file is <source-file-name>_test.go
  • Test functions need to have the "Test" prefix, and the next character in the function name should be capitalized

In the remainder of this section, we will look at three files and their associated tests:

  • variadic.go and variadic_test.go
  • addInt.go and addInt_test.go
  • nil_test.go (there isn't any source file for these tests)

Along the way, we will introduce any further concepts we might use.

主站蜘蛛池模板: 清流县| 凤凰县| 宁德市| 昆山市| 阳新县| 改则县| 清水河县| 杨浦区| 微博| 大同县| 阿图什市| 丽江市| 得荣县| 思茅市| 广汉市| 临清市| 三明市| 阿拉善盟| 文化| 泰兴市| 甘洛县| 屯门区| 昌黎县| 枝江市| 衡山县| 泗阳县| 东光县| 浑源县| 富川| 太仓市| 芷江| 道孚县| 抚州市| 丰台区| 白河县| 瑞丽市| 平邑县| 永善县| 资溪县| 剑川县| 乐至县|