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

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.

主站蜘蛛池模板: 余江县| 贵南县| 虎林市| 阳西县| 双江| 皋兰县| 崇信县| 竹山县| 浙江省| 兴安盟| 巴马| 呼和浩特市| 县级市| 绥江县| 靖西县| 嘉祥县| 托克托县| 城固县| 利川市| 光泽县| 永济市| 滨州市| 靖远县| 南通市| 喜德县| 安国市| 吉安市| 沐川县| 广平县| 望奎县| 自治县| 宁波市| 余江县| 林州市| 正宁县| 尖扎县| 贵德县| 平谷区| 汪清县| 福鼎市| 德清县|