For instance if I had a program with a bunch of methods.

        public class Dog{

            public boolean ishappy{..}

            public int weight{...}

        public static void main{
        Dog Max = new Dog

Is it best to use the main portion of the code to test, or write a completely separate program, which would be a client of the dog class, to test my code?


Ideally, you would use a test framework. A test framework will act as a separate client, but will handle a lot of things for you automatically.

You generally want to minimize the amount of code (especially logic) involved in your test code, because then you increase the chance that your test has a bug. Test frameworks help with this by reducing a lot of the boiler plate code required to get tests off the ground.

  • 4
    +1 for being on stack exchange and not testing dev deployment. Apr 5 '12 at 20:57

I always prefer to use a separate program to test. In .NET, there's the concept of test projects that provides a framework for unit tests, and in Perl, there are modules that give you the same sort of framework for testing. Just about any language will have something similar.

Keeping the test code separate gives you better distinction between the actual code and your tests. When you deploy your code to production, for example, what happens if you forget to remove a test? When you remove your tests, what happens when you want to rerun them? A separate test program/project will obviate many of these concerns.


In anything other than a trivial homework application, robust testing is critical to getting anywhere close to a correct application.

Here's an article from a .NET perspective that describes a testing framework that assists in ensuring that your application behaves the way you expect.

Also look around for other answers here regarding tests.

How Do You Test Your Software?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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