While unit testing with JUnit, I ran into a problem and I want to know if there is a standard solution.
I began using Podam to generate randomized test data, but a coworker correctly remarked that this could lead to unexpected unit test failures. On the one hand this is obviously bad and could make debugging a real pain. On the other hand it could be doing its job by highlighting a code problem.
I identified what I believe to be 3 approaches to solving the issue. Are any of these considered standard practice?
- Factory Method to Generate Randomized Test Data
- Factory Method to Return Standard Data
- Handcrafted approach, where there is no factory.
Further, I think each approach has the following pros and cons. Am I missing any important design considerations?
Pros:
- Robust testing, easy creation, semi-deterministic through overriding generated values.
- Easy creation, easy debugging.
- Moderately robust testing and moderately easy to debug.
Cons:
- Unexpected unit test failure (but at least you caught the issue). Harder to debug.
- Non-robust testing
- Human error, redundant and verbose code, less maintainable, diverse implementations.
Aucun commentaire:
Enregistrer un commentaire