我不明白为什么“go”找不到我的银杏测试文件
以下是我的结构:
events
├── button_not_shown_event.go
├── events_test
│ └── button_not_shown_event_test.go我的button_not_shown_event_test.go是什么样子?
package events_test
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ButtonNotShownEvent", func() {
BeforeEach(func() {
Expect(false).To(BeTrue())
})
Context("ButtonNotShownEvent.GET()", func() {
It("should not return a JSONify string", func() {
Expect(true).To(BeFalse())
})
})
})注意,我专门写了一个测试,这样它就会失败。
但是每次我运行银杏测试时,我都会得到以下错误
go test ./app/events/events_test/button_not_shown_event_test.go -v
testing: warning: no tests to run
PASS
ok command-line-arguments 1.027s所以很明显我在这里遗漏了一些东西。
有线索吗?
发布于 2017-06-27 14:39:58
你有一些问题。
(t *testing.T)。另外,经过几个人的大量评论。您可能需要阅读银杏文档,以确保您正在正确地跟踪他们的过程,以使您的测试设置正确。
发布于 2021-02-19 18:52:42
转到events_test目录并运行:
ginkgo bootstrap这是银杏的编写第一个测试文档
要为包编写银杏测试,首先必须引导银杏测试套件。假设你有一个书包叫“书”: $ cd path/to/book$银杏引导
ahillman3 3的建议对于正常测试是有效的,但是如果你用银杏进行测试,它就不适用了。
发布于 2021-09-12 02:31:05
我发现这些文档有点让人费解,在编写本文时它们不使用go模式,所以我将分享我正在使用的最小设置。为了简单起见,所有文件都在根项目目录中。
adder.go
package adder
func Add(a, b int) int {
return a + b
}adder_test.go
package adder_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "example.com/adder"
)
var _ = Describe("Adder", func() {
It("should add", func() {
Expect(Add(1, 2)).To(Equal(3))
})
})adder_suite_test.go
package adder_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestAdder(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Adder Suite")
}现在运行go mod init example.com/adder; go mod tidy
PS > go version
go version go1.17.1 windows/amd64
PS > go mod init example.com/adder
go: creating new go.mod: module example.com/adder
go: to add module requirements and sums:
go mod tidy
PS > go mod tidy
go: finding module for package github.com/onsi/gomega
go: finding module for package github.com/onsi/ginkgo
go: found github.com/onsi/ginkgo in github.com/onsi/ginkgo v1.16.4
go: found github.com/onsi/gomega in github.com/onsi/gomega v1.16.0最后,运行go test
Running Suite: Adder Suite
==========================
Random Seed: 1631413901
Will run 1 of 1 specs
+
Ran 1 of 1 Specs in 0.042 seconds
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS
ok example.com/adder 0.310s对于Linux来说,一切都一样。
https://stackoverflow.com/questions/44782807
复制相似问题