Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm about to write a simple script to test a dataset for certain conditions. I was designing it as a set of functions each one describing the condition to be tested and pass them to the test engine:

# The tester engine:
all(f(dataset) for f in conditions)

I realized that my approach was similar to unit testing. So, to avoid repeating myself, I am thinking of using my favorite unit testing framework instead.

  1. What do you think about that idea?
  2. Have any of you used an unit test framework for any other purpose than test code?
share|improve this question

2 Answers 2

It's an interesting approach. I'm assuming you are specifically looking for something like a nice summary of the properties your data set has.

e.g.

[X] Set is orthgonal array
[X] Set contains the letter s
[ ] No element has a depth greater than three generations.

Which technically I guess would be a set of Tests ^_^.

You can still test your business logic the same way you would test your custom asserts, and complex stub/mock classes e.g. with more unit tests that test the tester.

So . . . assumming you just want a quick way to get this type of information about your data set using some xUnit framework and the tap format or something probably wont end the world in thunder and flames, divide the earth by zero or anything too bad.

It's a little bit of a "I have a hammer" sort of a solution though.

Personally I would probably just search the nets a bit to see if anyone else has a good open source solution (http://cricket.sourceforge.net/ for example is vaguelly similiar) and if not whip up my own solution and release it.

The basic logic behind the unit test runner isnt too knarly. You use reflection to grab the list of methods in the current class and attributes to tag which methods you want to execute and which methods should be run before and after your "data questions".

share|improve this answer

How are you going to test the main code if is already wrapped in the unit test framework?

Any xUnit testing frameworks will report pass/fail states and do nothing about the result. If that is what you want, go for it. If you are going to use that data for anything, then do not use unit test. For example, you cannot attempt to "fix" the dataset such as, say, converting two-digits years into four digit years.

share|improve this answer
    
Good question, that is a dilemma. Yes, in my case i only want to know if the dataset pass/fail, and be able to define new tests in the future in a clean way. Thank you! –  jgomo3 Jan 20 '12 at 16:00
1  
+1. Also. Most UnitTest API's are quite confusing, since they're really about running a Suite of TestCase instances and providing a Summary report. A lot of off-target overhead for a simple task of checking a dataset's "quality" attributes. –  S.Lott Jan 20 '12 at 16:06
    
We had something similiar to this setup at kaplan. I had data integrity test cases that executed stored procedures on the database to check for specific unexpected data sets we occasionaly had troulbe with. The stored procedures would fix any malformed data if possible and return a t/f response along with an explanation message for a f response which was returned with the assert.fail call. Not the most ideal solution but it did give us a quick and dirty way to gauge db sanity over time by glancing are the cruise control logs for the db project. –  Keith Brings Jan 21 '12 at 9:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.