Junior — Middle
Have you had experience with automated testing in projects?
sobes.tech AI
Answer from AI
In Go projects, automated testing is usually implemented using the standard testing package. Experience may include:
- Writing unit tests for functions and methods using
testing.T. - Using test tables to check various input data.
- Running tests with the
go testcommand. - Using mocks and stubs to isolate components.
- Integration testing with external services.
Example of a simple test:
func Add(a, b int) int {
return a + b
}
func TestAdd(t *testing.T) {
result := Add(2, 3)
if result != 5 {
t.Errorf("Add(2, 3) = %d; want 5", result)
}
}
This approach allows for quick error detection and maintaining code quality.