Junior — Middle
What types of tests do you consider necessary to verify code quality?
sobes.tech AI
Answer from AI
To check the quality of Go code, several types of tests are usually used:
- Unit tests — verify individual functions or methods for correctness. They are fast and isolated.
- Integration tests — check the interaction of multiple components or modules together.
- End-to-end tests — simulate the entire application, testing business logic and user scenarios.
- Performance tests (benchmarks) — measure the speed and efficiency of the code.
Example of a simple unit 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)
}
}