Junior — Middle
Milliseid testitüüpe pead vajalikuks koodi kvaliteedi kontrollimiseks?
sobes.tech AI
Vastus AI-lt
To check the quality of code in Go, several types of tests are usually used:
- Unit tests — verify the correctness of individual functions or methods. They are fast and isolated.
- Integration tests — check the interaction of multiple components or modules together.
- End-to-end tests — simulate the full operation of the application, checking business logic and user scenarios.
- Performance tests (benchmarks) — measure the speed and efficiency of the code.
A simple example of a 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)
}
}