notexOPENOverview
Notex/Languages/Practice: Advanced Testing
05.24LESSON 24 OF 29 · 1 MIN READ

Practice: Advanced Testing

Always free to read

Now that you’ve seen the more advanced testing tools provided by Go, these exercises will give you a chance to try them out.

  1. In the ex4 directory, there is a file called wealth.go with a function called CalcWealth and a test for this function in the file wealth_test.go. Check the code coverage from this test. Examine the code and see if there’s a bug that wasn’t detected by the test. If so, add a test to demonstrate the bug, then fix the code.

  2. In the ex5 directory, there is a file called count.go. It contains three functions that perform the same task, CountWithFields, CountWithFieldsSeq, and CountManual. Write tests to validate that these functions work, then write benchmarks to compare their performance and amount of memory used.

  3. In the ex6 directory, there is a file called tracker.go with a type called Tracker. There is a test for this function in tracker_test.go. See if the test passes. If it does not, use the data race detector to figure out why, and fix the code to make it pass. Hint: fixing a concurrent bug might require you to think about lock acquisition and release lifetimes.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K