Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ギはGinkgoのギ

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

 ギはGinkgoのギ

Avatar for 木内 智史之介

木内 智史之介

February 01, 2021
Tweet

More Decks by 木内 智史之介

Other Decks in Programming

Transcript

  1. 自己紹介 • 木内 智史 ◦ twitter: @8823scholar • スキルセット ◦

    ruby、php、python、go、java、c++、c#、typescript、unity ◦ terraform • 趣味 ◦ 麻雀 ◦ スノーボード ◦ 投資 • 好きなテストフレームワーク ◦ rspec
  2. 従来のテスト (testing.T) package main import ( "testing" "github.com/stretchr/testify/assert" ) func

    TestCalcPoint(t *testing.T) { for _, tc := range []struct { name string text string oya bool tsumo bool res []int err error }{ { name: "タンヤオ", text: "s222678m333456p8 8", oya: false, tsumo: false, res: []int{1300}, err: nil, }, } { t.Run(tc.name, func(t *testing.T) { res, err := CalcPoint(tc.text, tc.oya, tc.tsumo) assert.Equal(t, tc.res, res) assert.Equal(t, tc.err, err) }) } }
  3. BDD的テスト (ginkgo) package main import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega"

    ) var _ = Describe("CalcPoint", func() { var text string var tsumo bool = false Context("タンヤオロン", func() { BeforeEach(func() { text = "s222678m333456p8 8" }) Context("子", func() { It("should be 1300", func() { Expect(CalcPoint(text, false, tsumo)).To(Equal(1300)) }) }) Context("親", func() { It("should be 2000", func() { Expect(CalcPoint(text, true, tsumo)).To(Equal(2000)) }) }) }) })
  4. テスト対象が俯瞰しやすくなる! • Describe: テスト対象 • Context: 条件の違い • It: 期待する動作

    これらの単語を用いて表現していくので、テスト対象や、その条件などを把握し やすくなる