DEV Community

Discussion on: Seven days of Go

Collapse
 
rhymes profile image
rhymes

Hi John,

I didn't unit test the DB layer. I tend not to unless the setup is über complicated. I use a testing db and run the functional tests on it.

I did it with Go using TestMain and a global testing connection (it sucks, I know) but the app is simple enough to make it work.

I have a TestMain per package like this:

func TestMain(m *testing.M) {
    TestSetupDatabase()
    result := m.Run()
    TestTeardownDatabase()

    os.Exit(result)
}

More about TestMain and tests: cs-guy.com/blog/2015/01/test-main/ - philosophicalhacker.com/post/integ... - medium.com/@povilasve/go-advanced-... - medium.com/@benbjohnson/structurin...

I still haven't gotten anything right, for example I want to separate tests in a "_test" package because now they live in the same package as the code and it makes me scared :D