Separating unit tests and integration tests in Go -


is there established best practice separating unit tests , integration tests in golang (testify)? have mix of unit tests (which not rely on external resources , run fast) , integration tests (which rely on external resources , run slower). so, want able control whether or not include integration tests when go test.

the straight-forward technique seem to define -integrate flag in main:

var runintegrationtests = flag.bool("integration", false     , "run integration tests (in addition unit tests)") 

and add if-statement top of every integration test:

if !*runintegrationtests {     this.t().skip("to run test, use: go test -integration") } 

is best can do? searched testify documentation see if there perhaps naming convention or accomplishes me, didn't find anything. missing something?

@ainar-g suggests several great patterns separate tests.

this set of go practices soundcloud recommends using build tags (described in "build constraints" section of build package) select tests run:

write integration_test.go, , give build tag of integration. define (global) flags things service addresses , connect strings, , use them in tests.

// +build integration  var fooaddr = flag.string(...)  func testtoo(t *testing.t) {     f, err := foo.connect(*fooaddr)     // ... } 

go test takes build tags go build, can call go test -tags=integration. synthesizes package main calls flag.parse, flags declared , visible processed , available tests.

as similar option, have integration tests run default using build condition // +build !unit, , disable them on demand running go test -tags=unit


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -