Test-driven basics
📖 Scenario: You are building a simple calculator function in Go. You will write the function step-by-step using test-driven development (TDD). This means you will first write tests that describe what the function should do, then write the function code to pass those tests.
🎯 Goal: Create a Go function called Add that takes two integers and returns their sum. You will write tests first, then write the function to pass those tests.
📋 What You'll Learn
Create a test function called
TestAdd in a file named main_test.go.Write a test case inside
TestAdd that checks if Add(2, 3) returns 5.Create the
Add function in main.go that takes two int parameters and returns their sum.Run the test to confirm it passes and print the result.
💡 Why This Matters
🌍 Real World
Writing tests before code helps catch mistakes early and ensures your code works as expected.
💼 Career
Test-driven development (TDD) is a common practice in software engineering jobs to improve code quality and reliability.
Progress0 / 4 steps