I'm just getting started with Golang and writing my first test suite.
I have a background in Rails, which has fantastic support for testing tools (Rspec, Cucumber, etc..), so I'm approaching my golang tests with a similar mindset (not sure if that's the right or wrong thing to do)
I have a User
data model (basically a struct) that reads records from a users
table in postgres and stores an array of them. (Essentially a really simple version of what ActiveRecord does in the Rails world)
I'd like to write a test that checks if the routine correctly reads from the DB and builds the models.
-
In almost every test suite I'll be connecting to the DB so I have a helper named
establish_db_connection
. Where can I place this so that it's centrally available to all my tests? -
Building off #1 - is there an equivalent of a
before
block or some setup/teardown method where I can establish a connection before every test? -
Lastly, how do I handle fixtures? Right now before each test I call a
clear_db
function that resets all tables and inserts some static data rows. I'd love to move away from fixtures and use factories to build data as needed (very similar toFactoryGirl
in Rails), but not sure how common that is in Golang. -
Is the built-in
go test
framework the best approach, or are there better alternatives?
Aucun commentaire:
Enregistrer un commentaire