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.

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
        Max.ishappy}}

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
add comment

3 Answers

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
add comment

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
4  
+1 for being on stack exchange and not testing dev deployment. –  Joshua Drake Apr 5 '12 at 20:57
add comment

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
add comment

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.