notexOPENOverview
Notex/Languages/Practice: Tests with Mocks and Stubs
05.28LESSON 28 OF 29 · 1 MIN READ

Practice: Tests with Mocks and Stubs

Always free to read

Now that you’ve learned about using mocks and stubs, complete these exercises to apply that knowledge to a sample application.

  1. In the ex7 directory, the notifier.go file contains a type called NotificationService with a method called Notify. Use a function field stub to write a table test to make sure this code properly handles correct data, invalid input, and a failed send.

  2. In the ex8 directory, the report.go file contains a type called ReportBuilder with a method called PriceSummary. ReportBuilder depends on a large interface (DataStore), but PriceSummary only used one method in the interface. Write a test to validate that PriceSummary works correctly.

  3. In the ex9 directory, the weather.go file contains a type called Client with a method called GetTemperature, which connects to a remote HTTP server to get weather data. Write a unit test to validate this method that doesn’t require you to run an external server.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

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