Define a logging interface in your main package, then pass an
implementation of the interface in your test that forwards writes to
t.Logf

On Tue, 30 Jan 2018, at 2:11 PM, Jérôme LAFORGE wrote:
> No, it is not possible to use t.Log within the code you want to test.> The 
> function IsBuggyEven is not defined to be used into testing scope,
> it is defined to be used into production context.> 
> Le mardi 30 janvier 2018 13:48:27 UTC+1, Jordan Krage a écrit :
>> Try using `t.Logf` instead of `fmt.Printf`.
>> 
>> On Saturday, January 27, 2018 at 6:03:13 AM UTC-6, Jérôme
>> LAFORGE wrote:>>> Of course, that was I already did. But I talk about the 
>> log into
>>> function I want to test (in the example of playground:  func
>>> IsBuggyEven) .>>> see: 
>>> https://play.golang.org/p/OWnEntLwfXa
>>> 
>>> 
>>> check 0 is even or odd, but I want see this log only for fail test
>>> case (i.e when i == 5) check 2 is even or odd, but I want see this
>>> log only for fail test case (i.e when i == 5) check 5 is even or
>>> odd, but I want see this log only for fail test case (i.e when i ==
>>> 5) --- FAIL: TestIsEven (0.00s)    --- FAIL: TestIsEven/5_is_even
>>> (0.00s)        /tmp/somewhere/mmoney_test.go:144: For 5, expected:
>>> false, actual: true FAIL FAIL    common/utils    0.044s Error: Tests
>>> failed.>>> 
>>> 
>>> Le samedi 27 janvier 2018 10:30:27 UTC+1, Tamás Gulácsi a écrit :
>>>> Use subtest (t.Run)> 


> --
>  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.

-- 
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