Sobes.tech
Junior — Middle

Milliseid meetodeid ja tööriistu kasutasite oma koodi õigsuse ja kvaliteedi kontrollimiseks?

sobes.tech AI

Vastus AI-lt

To verify the correctness and quality of Go code, the following methods and tools are commonly used:

  • Testing: writing unit tests using the testing package. This allows checking individual functions and methods.
  • Test coverage: the command go test -cover shows what percentage of the code is covered by tests.
  • Static analysis: golint checks code style, go vet detects potential errors.
  • Formatting: gofmt automatically formats code according to Go standards.
  • Profiling and debugging: pprof is used for performance analysis.

A simple test example:

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)
    }
}