在我下面的代码片段或https://play.golang.org/p/tLld-zNF2zp中,在块testValue内声明Describe,在块内更改BeforeEach。然后,用在。
ItExpect
测试按预期通过。从调试日志中,It总是显示testValue should be 0而不是testValue should be 3
package awesomeProject1_test
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("AwesomeProject1", func() {
var testValue int
BeforeEach(func() {
testValue = 3
})
Context("Correctness of testValue", func() {
It(fmt.Sprintf("testValue should be %d", testValue), func() {
Expect(testValue).To(Equal(3))
})
})
})
为什么testValue不是在It语句中改变而是在它里面?