首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >银杏测试没被发现?

银杏测试没被发现?
EN

Stack Overflow用户
提问于 2017-06-27 14:24:03
回答 3查看 4.4K关注 0票数 1

我不明白为什么“go”找不到我的银杏测试文件

以下是我的结构:

代码语言:javascript
复制
events
├── button_not_shown_event.go
├── events_test
│   └── button_not_shown_event_test.go

我的button_not_shown_event_test.go是什么样子?

代码语言:javascript
复制
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())
        })
    })
})

注意,我专门写了一个测试,这样它就会失败。

但是每次我运行银杏测试时,我都会得到以下错误

代码语言:javascript
复制
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

所以很明显我在这里遗漏了一些东西。

有线索吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-06-27 14:39:58

你有一些问题。

  1. 您没有导入测试包。这应该在Ginkgo生成的引导文件中。
  2. 引导文件还应该包括作为参数的testing.T函数。例如(t *testing.T)
  3. 看起来,您在银杏进程中跳过了一两个步骤,导致先前不存在依赖关系。引导/存根。

另外,经过几个人的大量评论。您可能需要阅读银杏文档,以确保您正在正确地跟踪他们的过程,以使您的测试设置正确。

票数 1
EN

Stack Overflow用户

发布于 2021-02-19 18:52:42

转到events_test目录并运行:

代码语言:javascript
复制
ginkgo bootstrap

这是银杏的编写第一个测试文档

要为包编写银杏测试,首先必须引导银杏测试套件。假设你有一个书包叫“书”: $ cd path/to/book$银杏引导

ahillman3 3的建议对于正常测试是有效的,但是如果你用银杏进行测试,它就不适用了。

票数 2
EN

Stack Overflow用户

发布于 2021-09-12 02:31:05

我发现这些文档有点让人费解,在编写本文时它们不使用go模式,所以我将分享我正在使用的最小设置。为了简单起见,所有文件都在根项目目录中。

adder.go

代码语言:javascript
复制
package adder

func Add(a, b int) int {
    return a + b
}

adder_test.go

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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来说,一切都一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44782807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档