Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang Testing > cant load package

Tags:

go

bdd

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()
    }
}
like image 434
R.J. Robinson Avatar asked Mar 17 '23 13:03

R.J. Robinson


1 Answers

You have

package main

func main() {}

in file calculator.go.

and

package calculator

in file calculator_test.go.

They should both be

package main
like image 99
peterSO Avatar answered Mar 25 '23 03:03

peterSO