Junior — Middle
What methods and approaches do you use to verify the functionality of your code?
sobes.tech AI
Answer from AI
To check the functionality of code in Go, I use several approaches:
- Unit testing with the
testingpackage. I write tests for functions and methods, checking different cases. - Logging and debugging — I add log outputs using
logorfmtto track the state. - Profiling and performance analysis — using
pprofto identify bottlenecks. - Integration tests — I verify the interaction of multiple components.
- Using static analysis —
go vet,golintto find potential errors.
Example of a simple test:
func TestSum(t *testing.T) {
got := Sum(2, 3)
want := 5
if got != want {
t.Errorf("Sum(2, 3) = %d; want %d", got, want)
}
}