Including Unit Test Code in Classes

Why don't we include unit tests _inside_ a class?  The test would be exposed via a _Testable_ interface.  Methods would include RunTests() and return a object reporting success or failure.

While reading a post about testing, I had an epiphany of sorts.  Instead of making all private methods public _just_ to facilitate testing, why not make an interface that supports testing.  Much like electrical equipment that ships with a self test mode, the test could be run "in the field" to make sure it works OK.

There are some small issues to figure out.  Which testing framework do you support?  Does the extra test code bloat the production code?  However, I wonder if this wouldn't solve a lot of problems causes because the test is separate from the code.  Especially unit code testing which is by definition very closely tied to the code under test.

Do you see any other problems with this approach?  Is this a good idea or not?

Comments (0)

Leave a comment...

About

[Insert Witty Saying Here]