lundi 6 mars 2017

Are Test Data Factory Methods Dangerous or Beneficial?

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?

  1. Factory Method to Generate Randomized Test Data
  2. Factory Method to Return Standard Data
  3. 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:

  1. Robust testing, easy creation, semi-deterministic through overriding generated values.
  2. Easy creation, easy debugging.
  3. Moderately robust testing and moderately easy to debug.

Cons:

  1. Unexpected unit test failure (but at least you caught the issue). Harder to debug.
  2. Non-robust testing
  3. Human error, redundant and verbose code, less maintainable, diverse implementations.

Aucun commentaire:

Enregistrer un commentaire