Running tests
📖 Scenario: You are working on a small Go program that adds two numbers. To make sure your code works correctly, you want to write a simple test.
🎯 Goal: Create a Go function that adds two integers, then write a test function to check if it returns the correct result.
📋 What You'll Learn
Create a function called
Add that takes two integers and returns their sum.Create a test function called
TestAdd in the same package.Use the
testing package and t.Errorf to report errors.Run the test using
go test and print the result.💡 Why This Matters
🌍 Real World
Writing tests helps catch mistakes early and makes your Go programs more reliable.
💼 Career
Testing is a key skill for software developers to ensure code quality and maintainability.
Progress0 / 4 steps