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

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.

主站蜘蛛池模板: 星子县| 兰坪| 德兴市| 尤溪县| 江川县| 灵山县| 瑞安市| 连江县| 邓州市| 利川市| 梧州市| 龙里县| 华宁县| 蒲江县| 衡阳市| 崇阳县| 喀喇| 高碑店市| 什邡市| 商城县| 林州市| 塘沽区| 栖霞市| 中阳县| 西贡区| 老河口市| 澄迈县| 宝清县| 陇南市| 庆云县| 兰州市| 乌拉特中旗| 宝兴县| 香港 | 重庆市| 比如县| 五华县| 神池县| 恩平市| 敦煌市| 五大连池市|