From the course: Programming with Go Modules
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Testing package source code - Go Tutorial
From the course: Programming with Go Modules
Testing package source code
- [Instructor] The Go programming language comes with a built-in test framework and tools that lets programmers test their source code as part of the development workflow. As a review, Go tests are written as normal Go functions with specific name pattern, and function signature. The function name starts with a prefix test followed by a descriptive suffix for the test. The function takes the pointer to type testing.T, which provides access to the testing framework functionalities at runtime. Go tests are especially useful when creating library packages like our search package. Tests can provide a way to validate that the code being developed functions as intended before we even use it in a program. So now let's create our own test. Okay, now we're back in the IDE. The first thing we're going to do is add a test for the search functionality that we added earlier. So let's create a new file and we're going to call that file search_test.go to indicate that it is a test file. And next…