I am building a Ruby gem that implements the Composition design pattern. The tree-structure has 3 levels in the hierarchy: Trunk, Branch, Leaf. Branch and Leaf each have a reference to their @parent.
To generate test data, I am using FactoryBot.
Some of the functions in the Leaf node rely on code/data in the Branch and Trunk nodes. However, in my minutest unit tests, I am only generating test data for Leaf nodes instead of populating the entire tree.
In this scenario, would it be best practice to write my Leaf unit tests to populate the entire tree instead of just the leaf? I figure that is the easy solution, but would that not defeat the purpose of having isolated unit tests?
Alternatively, is it best practice to avoid testing those Leaf methods that rely on calls to its parent in the unit test and instead place those in an integration test?
Thanks for the input.
Aucun commentaire:
Enregistrer un commentaire