FAQ
Hi,

I can use t.Log to print messages inside my test functions, and use test -v
to see those messages during testing. But how do I print a message from
inside init() inside my test file? And similarly, how do I print test
messages inside my package functions and package init()?

I want to do this because I want to know when those functions are entered
during testing (and in what sequence).

For example, I want to print a message during testing everywhere there is
an XXX in these files:

foo.go:

package main

func init() {
   // XXX
}

func Bar() {
   // XXX
}

func main() {
   Bar()
}

foo_test.go:

package main

import "testing"

func init() {
   // XXX
}

func TestFoo(t *testing.T) {
   t.Log("inside TestFoo() in foo_test.go")
}

Any ideas how I can accomplish this?

Many thanks!

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Oct 10, 2015 at 8:23 pm

    On Sat, Oct 10, 2015 at 9:24 AM, wrote:
    I can use t.Log to print messages inside my test functions, and use test -v
    to see those messages during testing. But how do I print a message from
    inside init() inside my test file? And similarly, how do I print test
    messages inside my package functions and package init()?
    fmt.Printf?

    If that doesn't work you'll need to explain a bit more about what you are after.

    Ian

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 10, '15 at 8:17p
activeOct 10, '15 at 8:23p
posts2
users2
websitegolang.org

2 users in discussion

Andrewinfosec: 1 post Ian Lance Taylor: 1 post

People

Translate

site design / logo © 2022 Grokbase