Closed7

ginkgo v2調査

douglasdouglas

Describe("Something expensive", Serial, func() {}) と書くことで並列実行時でも他プロセスとは同時に実行しないようにできる。

実行タイミングは並列実行できるスイートがすべて完了した後になる。

douglasdouglas

BeforeEachAfterEach はすべてのスペックの実行前と実行後に動作するが、Contaniner Nodes内のスペックに対して一度だけ実行したい処理がある場合にも毎回実行されてしまう。(たとえばDBの初期化処理)
これはissueにもなっていた。
https://github.com/onsi/ginkgo/issues/70

Contaniner Nodesの中スペックに対して一度だけ実行したい処理の場合はBeforeAllAfterAllが使える。
ただし、Ordered Containersに対してのみ使える。
Orderd Container内のスペックは実行の順番がランダム化さらず記述された順に実行される。
また、OrderedをBeforeEach/JustBeforeEach/AfterEach/JustAfterEach につけることでOrdered Container内のスペックに対して全体で1回だけ実行するようにできる。

Describe("Something", Ordered, func() {
	BeforeEach(OncePerOrdered, func() {})

	Context("context", Ordered, func() {
		BeforeAll(func() {})

		It("spec1", func() {})
		It("spec2", func() {})
	})

	Context("context", , func() {
		It("spec3", func() {})
		It("spec4", func() {})
	})
})

この場合はBeforeEachはOrdered Contextのスペックを実行する前に1回、spec3とspec4を実行する前に1回づつ実行される。

https://onsi.github.io/ginkgo/#setup-in-ordered-containers-beforeall-and-afterall

When we introduced this example we recommended condensing the tests into a single It and using By to document the test.
と公式ドキュメントにあるので公式的にはItは1つにしてByで分割するのをおすすめしてる?

douglasdouglas

フィルタリング

ペンディング(常に実行されない)

// With the Pending decorator:
Describe("these specs aren't ready for primetime", Pending, func() { ... })
It("needs work", Pending, func() { ... })
It("placeholder", Pending) //note: pending specs don't require a closure
DescribeTable("under development", Pending, func() { ... }, ...)
Entry("this one isn't working yet", Pending)

// By prepending `P` or `X`:
PDescribe("these specs aren't ready for primetime", func() { ... })
XDescribe("these specs aren't ready for primetime", func() { ... })
PIt("needs work", func() { ... })
XIt("placeholder")
PDescribeTable("under development", func() {...}, ...)
XEntry("this one isn't working yet")

スキップ(条件をつけて実行しない)

It("should do something, if it can", func() {
  if !someCondition {
    Skip("Special condition wasn't met.")
  }
  ...
})

フォーカス : 指定したスペックだけを実行する

// With the Focus decorator:
Describe("just these specs please", Focus, func() { ... })
It("just me please", Focus, func() { ... })
DescribeTable("run this table", Focus, func() { ... }, ...)
Entry("run just this entry", Focus)

// By prepending `F`:
FDescribe("just these specs please", func() { ... })
FIt("just me please", func() { ... })
FDescribeTable("run this table", func() { ... }, ...)
FEntry("run just this entry", ...)

スペックラベル : ginkgo --label-filter=QUERYコマンドでラベルを指定して実行をフィルタできる

Describe("Storing books", Label("integration", "storage"), func() {
  It("can save entire shelves of books to the central library", Label("network", "slow", "library storage"), func() {
    // has labels [integration, storage, network, slow, library storage]
  })

  It("cannot delete books from the central library", Label("network", "library storage"), func() {
    // has labels [integration, storage, network, library storage]    
  })

  It("can check if a book is stored in the central library", Label("network", "slow", "library query"), func() {
    // has labels [integration, storage, network, slow, library query]    
  })

  It("can save books locally", Label("local"), func() {
    // has labels [integration, storage, local]    
  })

  It("can delete books locally", Label("local"), func() {
    // has labels [integration, storage, local]        
  })
})

ファイル名によるフィルタリング

ginkgo --focus-fileginkgo --skip-file コマンドでファイル名を指定して実行する。

説明文ベースによるフィルタリング

ginkgo --focus=REGEXPginkgo --skip=REGEXP コマンドでノードの説明を指定してフィルタして実行する。

このスクラップは2022/10/26にクローズされました