Skip to content

Conversation

@t0w4
Copy link

@t0w4 t0w4 commented Jun 26, 2018

  • 1回目の宿題のテストを作ってみて下さい
  • テストのしやすさを考えてリファクタリングしてみる
  • テストのカバレッジを取ってみる
  • テーブル駆動テストを行う
  • テストヘルパーを作ってみる

テストヘルパー
0bf8f77
-> interfaceをDecode, Encode単位に分割

テーブル駆動テスト
->b73b1d4

リファクタリング
main処理からflagのパース,画像変換コマンド切り出し
->70d7d8b

参考:
https://github.com/hashicorp/atlas-upload-cli
https://deeeet.com/writing/2014/12/18/golang-cli-test/

@t0w4 t0w4 self-assigned this Jun 26, 2018

// 画像変換テスト
func TestConvertImage(t *testing.T) {
t.Helper()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Helper() はヘルパー関数側で呼ぶので、この場合 SetupTestConvertImage() の中で呼んであげるのが適切かと思います

}

// 画像変換テストの前後で変換後のファイルを削除する
func SetupTestConvertImage(t *testing.T, files []string) func() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テスト用なのでわざわざ public にする必要はなさそう

file, err := os.Open(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "file open error: %v\n", err)
return err
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一般的な話としてエラーを返してるならここで標準エラーに出力する必要はない気がしますね(エラーを出力するなら ConvertImage() を呼んだ側でやるほうが自然)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants