You need to sign in to do that
Don't have an account?
Ryanh
Testing Best Practices -- Reusable code in unit tests?
Given that unit test methods are required to be static and void, I find that I have a lot of duplicated code for the test setup. If I write 3 unit tests for one method because there are different branches in the logic of that method, I'm copying and pasting the data setup portion of the test case into each of the three unit tests.
There's gotta be a better way! Help? Ideas?
Thanks
I have struggled with this as well. The solution I came up with, not ideal, but better than nothing, was to create an additional "setuptest" method that does all of my object creation. I create top level static variables and objects and then populate them with my setuptest method execution.
For each branch unit test, I call the setuptest method, and the objects are created.
All Answers
I have struggled with this as well. The solution I came up with, not ideal, but better than nothing, was to create an additional "setuptest" method that does all of my object creation. I create top level static variables and objects and then populate them with my setuptest method execution.
For each branch unit test, I call the setuptest method, and the objects are created.