If you need to test your code that way it needs a better design. If the 
internal code within the function under test is trivial then testing purely the 
outer function will suffice. If the internal code is that complex it should be 
its own non-exported function that can be documented and tested in isolation. 
It will pay dividends to future maintainers. 

> On Mar 1, 2020, at 10:21 AM, Warren Stephens <wsteph...@prognoshealth.com> 
> wrote:
> 
> 
> // I don't want to get into the specific syntax of the test code directly,    
> // but a test would start execution here, supplying "lines" and "thing2"
> //
>     mystep2 with: lines, thing2  // <---------- hide all local variables from 
> above except for lines and thing2
> 
>     mymap := make(map[string]int)
>     for _, line := range lines {
>             if strings.Contains(line, thing2) {
>                     count := strings.Count(line, thing2)
>                     mymap[line] = count
>              }
>     }
> 
> // and the test would end here -- because the next line is another "with" (or 
> return) statement
> // it would be able to do Asserts and such on the variables within the scope 
> of this code segment
> 
> Ian,
> 
> An alternative approach would be to have:
> 
>    mystep2 with: lines, thing2 => mymap
> 
> to specify all of the intermediate variables of interest for the test.
> 
> These testable code chunks, delimited by with statements, act like hidden 
> funcs.  The actual call could be something like test_doSomeStuff@mystep2
> 
> Warren
> 
>> 
>> I feel like there is something missing here.  How do you write a test 
>> that uses a with statement? 
>> 
>> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/f18a9af6-240b-4f3c-a011-6d68ed69784e%40googlegroups.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/FF19D324-701B-4FD3-AE8F-884851E90F26%40ix.netcom.com.

Reply via email to