From the course: Go for Developers: Practical Techniques for Effective Coding

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Testing basics

Testing basics

- Go ships with a powerful testing framework, and as such, there is a strong emphasis on testing in Go. Tests in Go are written in the Go language, so there is no need to learn another syntax. Because the language was designed with testing in mind, it tends to be easier to create and understand tests in Go than in most other languages. As with any statically typed language, the compiler will catch a lot of bugs for you. However, it cannot ensure that your application is bug-free in its logic. In Go, there are several tools to ensure your code is not only bug-free, such as tests, but also tools to show which part of your code has been tested and which has not. When creating the code for a test, that code will have to be placed in a test file. Go identifies a file as being a test file with the _test.go suffix. A nice side effect of this naming convention is that all test files will appear in the file list right next to the file they're usually testing. For example, here we see a file…

Contents