Il giorno sabato 4 febbraio 2017 23:59:34 UTC+1, Tong Sun ha scritto:
>
> I know all go testing code are invoked with "*go test*", however, I want 
> to easily test out some of the test code of the package I'm trying, so the 
> easiest way is to test them out as-is, but with "*go run*" instead. Is it 
> possible, or how can I make such thing possible? 
>
> For e.g., here is a piece of test code I that want to test out (just for 
> illustration), 
>
> func TestSomething(t *testing.T) {
>  fmt.Println("Say hi")
>  t.Log("Say bye")
>  t.Error("Error is equivalent to Log followed by Fail")
> }
>
>
> and I want to test out in my own program like this:
>
> package main
> func main() {
> }
>
>
> how can I make it possible?
>
>
It is possible, but not with `go run` but instead with `go test`.

Add a _test prefix to your test file and run it with go test.
As an example:
    go test code_test.go

Is there any reason why you want to run it with go run?
If you need, you can define a TestMain function, see
https://golang.org/pkg/testing/#hdr-Main


Manlio 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to