Unit tests
One of the fundamental aspects of testing your application starts with unit tests. Unit tests focus on individual components, verifying that each function or method works as intended. In Go, unit tests are written using the built-in testing package, making it easy to define test functions and assertions.
You will typically define positive and negative unit tests. For example, if you have a function to concatenate several strings together, then you would have some positive test cases, such as "hi " + "sam" = "hi sam", and "bye," + " sam" = "bye, sam"
. You would also add a few negative test cases that verify that an error occurred for input, such as "hi" + "there" expecting the result of "hi sam"
. This is not equivalent, nor what we would expect as output, so our negative test case would expect an error to arise.
You can also consider edge cases, such as concatenating strings that...