jwjacobson / jazztunes

a jazz repertoire management app
https://jazztunes.org
GNU General Public License v3.0
3 stars 1 forks source link

Write tests for Tune Edit #45

Closed ryaustin closed 9 months ago

ryaustin commented 9 months ago

Follow the pattern we used today to write a test for Tune Edit:

jwjacobson commented 9 months ago

As I work on this I'm following the model of the previous two tests and am wondering about code repetition. It looks like each test starts from 0, i.e. it has to create the user, create the tune, etc. Is it possible to make this a little more modular by having say a create_user function, create_tune function so that the tests don't end up being so repetitive? Or is this not really a concern with tests?

bbelderbos commented 9 months ago

This is where fixtures come into play: https://pybit.es/articles/pytest-fixtures - they allow you to write repeated set up code.

Related @ryaustin clinic on Factory boy (might not need yet but good to know!) https://pybites.circle.so/c/pybites-coaching-calls/sections/117462/lessons/394723

bbelderbos commented 9 months ago

Seems you struggled a bit with setup you said @jwjacobson so here is a reference video just in case: https://www.youtube.com/watch?v=L5jWFU2sVXQ

ryaustin commented 9 months ago

Good on you for recognizing all that repetition @jwjacobson. Fixtures are your key tool here and Bob provided some great resources above. Fixtures are fine to move into now since the repetition is already a concern of yours but I'd recommend you not worry too much about optimizing everything just yet. Get into the habit of writing tests & understanding the code you have to maintain, optimizing will come.