我尝试测试用Go语言编写的代码,但我不断收到此错误,但我不知道为什么

Mario Checker:

首先,我自己编写了一个名为trace的程序包,它有两个文件,以运行我写到终端的整个程序包:

go test -cover

但是会出现此错误:

--- FAIL: TestNew (0.00s)
    tracer_test.go:19: We haven't written our test yet
FAIL
coverage: 100.0% of statements
exit status 1
FAIL    gizmo/go/src/trace      0.172s

这是跟踪包中两个文件的代码:第一个,tracer.go

package trace

import (
    "io"
    "fmt"
)

//Tracer is the interface that describes an object capable of tracing events throughout code

type Tracer interface {
    Trace(...interface{})
}


type tracer struct {
    out io.Writer
}

func (t *tracer) Trace(a ...interface{}){
    fmt.Fprint(t.out, a...)
    fmt.Fprintln(t.out)
}

func New(w io.Writer) Tracer {
    return &tracer{out: w}
}

第二个,tracer_test.go

package trace

import (
    "testing"
    "bytes"
)

func TestNew(t *testing.T) {
    var buf bytes.Buffer
    tracer := New(&buf)
    if tracer == nil {
        t.Error("Return from New should not be nil")
    } else {
        tracer.Trace("Hello trace package.")
        if buf.String() != "Hello trace package.\n" {
            t.Errorf("Trace should not write '%s'.", buf.String())
        }
    }
    t.Error("We haven't written our test yet")
}

我真的很想有人帮助我,我被困住了。(我不希望测试失败但要通过)。

保罗·汉金:

go cover除了生成覆盖率信息外,还运行测试并报告其成功。看来您的选择是忽略FAIL测试失败消息,或者删除t.Error导致失败的行。

一个更复杂的解决方案是添加一个标志(或构建标签),该标志根据其值有条件地使不完全测试失败。然后可以在运行时设置标志go cover但就我个人而言,我不会理会任何如此复杂的事情。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我不断收到此错误消息,但我不知道为什么

我在 CSS 中不断收到此错误,但我不知道为什么

我不断收到 SyntaxError 但我不知道为什么

这是我的最终代码。我最终多次收到错误消息,但我不知道为什么

我的代码中不断出现“未捕获范围”错误,但我不知道为什么

我收到 mysqli 错误 1064 但我不知道为什么

我正在尝试学习 python 但我的代码不起作用,我不知道为什么

我收到“ num”的UnboundLocalError,但我不知道为什么

收到int错误,但我不知道为什么。我的文件没有多余的空格

我不知道为什么,但我收到错误:“AttributeError: 'super' 对象没有属性 '__getattr__'”

我的Matlab代码不起作用,但我不知道为什么?

Netsuite:我不知道为什么我的 query.load 收到此错误

变异观察者单元测试失败,但我不知道为什么

导致单元测试失败的“如果”语句,但我不知道为什么

为什么我收到这个错误?似乎我在 s1.grade_level 中有错误,但我不知道为什么

运行此程序时出现“无法到达的代码错误”,但我不知道为什么

反应类型错误,useState 不起作用。但我不知道为什么

不知道为什么我会收到此错误“SyntaxError: invalid token”?

不知道为什么我收到 StopIteration 错误

我正在尝试进行此sql更新查询,但我不知道为什么它不起作用

我不知道为什么我在 jsp 文件中收到这个简单代码的错误

Python:我不断收到广播错误,但我不知道如何解决它

我的查询在wordpress中返回null,但我不知道为什么

导航菜单是透明的,但我不知道为什么。我要背景

我的查询在wordpress中返回null,但我不知道为什么

我的主要功能是无限循环重复,但我不知道为什么

我遇到内存泄漏,但我不知道为什么

我的准确度是0.0,但我不知道为什么?

我的应用程序崩溃了,但我不知道为什么?