How to force Go to restart tests and disable result caching?
Hi everyone! I just started learning Go and encountered a very strange problem when writing tests. I have a simple package with a function that returns the current time. I wrote a test that checks that the function returns a time close to the current time. Here is my code:
```go
// timeutils.go
package timeutils
import "time"
func GetCurrentTime() time.Time {
return time.Now()
}
```
```go
// timeutils_test.go
package timeutils
import (
"testing"
"time"
)
func TestGetCurrentTime(t *testing.T) {
now := time.Now()
result := GetCurrentTime()
diff := result.Sub(now)
if diff > time.Second || diff < -time.Second {
t.Errorf("GetCurrentTime() = %v, want time close to %v", result, now)
}
}
```
The problem is that when I ru
No answers yet.
Log in to leave an answer
Blogs