PaolaJ.
PaolaJ.

Reputation: 11582

Cannot call tests inside packages other than main

I am writing tests for my go code and inside sender folder, sender package I have added exposed_api_test.go ( also tried exposed_api_test.go because I have code in exposed_api.go)

package sender

import (
    "log"
    "testing"

    "github.com/stretchr/testify/assert"
)

func TestTimeConsuming(t *testing.T) {

   assert.Equal(t, "test", "test1")

}

and when I run build and run command go test my_project I get ? my_project [no test files] When I put test out of this package ( in main package same test but package main ) and execute same command I get that test from main executed. What is a problem and how to call tests inside other packages other than main ?

Upvotes: 0

Views: 59

Answers (1)

t j
t j

Reputation: 7324

Try this:

go test my_project/...

Or if you are within your project:

go test ./...

Upvotes: 1

Related Questions