英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论