tdd

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Greet

func Greet(name string)

这种函数无法测试 只能测试有没有运行或编译错误,但无法测试是否打印了正确的语句

func GreetTestable

func GreetTestable(writer io.Writer, name string)

可测试接口 - 依赖注入 fmt.Printf函数内部调用的Fprintf函数 而FPrintf内部会将后面字符串写入到第一个参数的缓冲区中 os.Stdout和bytes.Buffer均实现了io.Writer接口

因此,测试时writer传入一个buf bytes.Buffer,实际使用时打印的语句被写入buf,这样就可以获取到要打印的内容了 在实际使用时writer传入os.Stdout即可打印到标准输出。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL