Golang 测试 > 无法加载包

huangapple go评论93阅读模式
英文:

Golang Testing > cant load package

问题

我遇到了Go语言内置测试的问题。

我一直收到这个错误。

> go test
> can't load package: package .: found packages main (calculator.go) and calculator (calculator_test.go) in

calculator.go

package main

func main() {

}

calculator_test.go

package calculator

import "testing"

func TestAdd(t *testing.T) {
    result := Add(1, 3)
    if result != 4 {
        t.Fail()
    }
}
英文:

I am having an issue with the built in testing for go lang.

I keep getting this error.

> go test
> can't load package: package .: found packages main (calculator.go) and calculator (calculator_test.go) in  

calculator.go

package main

func main() {

}

calculator_test.go

package calculator

import "testing"

func TestAdd(t *testing.T) {
	result := Add(1, 3)
	if result != 4 {
		t.Fail()
	}
}

答案1

得分: 7

你在calculator.go文件中有以下代码:

package main

func main() {}

calculator_test.go文件中有以下代码:

package calculator

它们两个都应该改为:

package main
英文:

You have

package main

func main() {}

in file calculator.go.

and

package calculator

in file calculator_test.go.

They should both be

package main

huangapple
  • 本文由 发表于 2014年12月22日 12:20:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/27596539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定