No, you do not need specific associations for testing modules, even if your goal is to fully test your application (what you need). Associations are only an implementation; they exist to support behavior, and testing this behavior always fully verifies the existence of associations. Separate unit unit tests of associations add no value.
If you practice test-based development and in the middle of implementing some kind of behavior that requires association, it might be helpful to write a unit test for the association, get it to pass, and come back to finish the behavior test. Usually I donβt find that I need it, because in Rails, adding a link to existing models or even adding a new model is quite simple, but some people like intermediate test support. However, once the behavior has been implemented, I will remove the association check, since I would use an extra test.
I wrote more about the usefulness of directly testing various aspects of ActiveRecord models in this answer and this answer .
source share