title: Unit testing with random data
body: <p>I've read that generating random data in unit tests is generally a bad idea (and I do understand why), but testing on random data and then constructing a <em>fixed</em> unit test case from random tests which uncovered bugs seems nice. However I don't understand how to organize it nicely. My question is not related to a specific programming language or to a specific unit test framework actually, so I'll use python and some pseudo unit test framework. Here's how I see coding it:</p>
  
  <pre><code>def random_test_cases():
     datasets = [
         dataset1,
         dataset2,
         ...
         datasetn
     ]
     for dataset in datasets:
         assertTrue(...)
         assertEquals(...)
         assertRaises(...)
         # and so on
  </code></pre>
  
  <p>The problem is: when this test case fails I can't figure out which dataset caused failure. I see two ways of solving it:</p>
  
  <ol>
  <li>Create a single test case per dataset — the problem is load of test cases and code duplication.</li>
  <li>Usually test framework lets us pass a message to assert functions (in my example I could do something like <code>assertTrue(..., message = str(dataset))</code>). The problem is that I should pass such a message to each assert, which does not look like elegant too.</li>
  </ol>
  
  <p>Is there a simpler way of doing it?</p>