我正在編寫一個測試來斷言函數在無效輸入時發生恐慌,但 Ginkgo 將恐慌記錄為失敗而不是預期的通過結果。func ParseUnixTimeString(unixTimeString string) time.Time { i, err := strconv.ParseInt(unixTimeString, 10, 64) if err != nil { panic(fmt.Sprintf("could not parse time: %s", err.Error())) } return time.Unix(i, 0)}func TestFormat(t *testing.T) { gomega.RegisterFailHandler(ginkgo.Fail) ginkgo.RunSpecs(t, "Format Suite")}var _ = ginkgo.Describe("Format Tests", func() { ginkgo.Describe("When formatting the date", func() { ginkgo.It("should panic if the time can't be formatted", func() { gomega.Expect( tools.ParseUnixTimeString("2314321432143124223432434")).To(gomega.Panic()) })})哪個返回(濃縮):?! [PANICKED] [0.002 seconds][It] should panic if the time can't be formattedTest Panickedcould not parse time: strconv.ParseInt: parsing "2314321432143124223432434": value out of rangeRan 1 of 1 Specs in 0.002 secondsFAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped如何正確測試 Ginkgo/Gomega 中的恐慌?
Ginkgo/Gomega 恐慌測試失敗
12345678_0001
2022-12-19 21:22:32