I am writing unit tests for a fairly simple function that depends on a fairly complicated set of data. Essentially, the object I am manipulating represents a graph and this function determines whether to chart a line, bar, or pie chart based on the data that came back from the server.This is a simplified version, using jQuery:setDefaultChartType: function (graphObject) {  var prop1 = graphObject.properties.key;  var numCols = 0;  $.each(graphObject.columns, function (colIndex, column) {    numCols++;  });  if ( numCols > 6 || ( prop1 > 1 && graphObject.data.length == 1) ) {    graphObject.setChartType(line);  } else if ( numCols <=6 && prop1 == 1 ) {    graphObject.setChartType(bar);  } else if ( numCols <=6 && prop1 > 1 ) {    graphObject.setChartType(pie);  }}My question is, should I use mock data that is procured from the actual database? Or can I just fabricate data that fits the different cases?I'm afraid that fabricating data will not expose bugs arising from changes in the database, but on the other hand, it would require a lot more effort to keep the test data up-to-date that I'm not sure is necessary.
Is application-specific data required for good unit testing?
unit testing;mocking
If you already have data that you can anonymise, using it that will be quicker than chasing down a BA (Business Analyst) to review your test data to make sure that you have appropriate coverage.I'm afraid that fabricating data will not expose bugs arising from changes in the databaseThat's not the point of unit testing, if your tests depend on LIVE data, then it's an integration test.For your unit tests, get a snapshot of data that covers ALL situations (or as many as possible that already exist) from the database and use that for your unit tests, and fabricate any edge cases with the help of a BA.If your requirements don't change, your tests won't get out of date. If your requirements do change, you'd need to update the tests anyway.