Middle+
What types of tests have you had to write?
sobes.tech AI
Answer from AI
I had to write several types of tests in Go:
- Unit tests — for checking individual functions and methods. Used the standard testing package, wrote tests with different input data, and checked the expected results.
- Integration tests — for verifying interaction between components, such as with databases or external services. Often used mock objects or test databases.
- Performance tests — using benchmarks to evaluate the speed of critical functions.
Example of a simple unit test in Go:
func TestSum(t *testing.T) {
result := Sum(2, 3)
if result != 5 {
t.Errorf("Expected 5, got %d", result)
}
}