Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
+1 for being on stack exchange and not testing dev deployment. – Joshua Drake 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.

share|improve this answer

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?

share|improve this answer

Your Answer


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.