Sobes.tech
Senior

Did you cover your code with tests?

sobes.tech AI

Answer from AI

Yes, I always try to cover my code with tests. In Go, it is convenient to use the built-in testing package.

Test coverage helps identify errors early, simplifies refactoring, and increases code reliability.

Here's a simple example of a test in Go:

func Add(a, b int) int {
    return a + b
}

func TestAdd(t *testing.T) {
    result := Add(2, 3)
    if result != 5 {
        t.Errorf("Expected 5, got %d", result)
    }
}

This approach allows for automating the verification of function correctness.