Tutorial 3

Tutorial 3 - CS 134 Tutorial 3: Testing, JUnit, and the Dr....

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 134 Tutorial 3: Testing, JUnit, and the Dr. Java Debugger CS 134 Tutors Winter 2008 1 What is Testing? 1.1 Purpose of Testing The purpose of testing is not to verify that the code is correct. Its purpose is to find flaws in your program. In fact, a successful test is one where you have found an error in the program. 1.2 Mindset of a Tester Since all programmers believe that their code is perfect, it is often difficult for the programmer to design test cases. In the real world, testers are often separate from the programmers. This will ensure that flaws in the program can be found efficiently. For the purposes of CS134, the tester and programmer is typically the same person. Here are a few hints to help you test better: Write tests before coding the program: After you’ve written your program, you may find yourself writing test cases that you know your program will pass. By writing tests ahead of time, you will be forced to base your tests on the specification requirements instead of on your code. Test early and test often: You should try to test each class once you’ve finished writing it. Also, try to test each method once you’ve finished implementing it. It ensures that the rest of your program will be using a correct class. Test after every change: If you change one bit of the code, it is wise to test all the test cases again since your change may have caused another bug that was eliminated earlier in testing, or it may have caused an entirely new one. Send messages to console: If your test cases make use of multiple methods or if one of the methods is very long, consider sending messages to the console. This helps you pinpoint specific sections of code that are failing. Note: use the System.err.println() command instead of System.out.println() . This is because
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2010 for the course CS CS134 taught by Professor Cl during the Fall '07 term at Waterloo.

Page1 / 6

Tutorial 3 - CS 134 Tutorial 3: Testing, JUnit, and the Dr....

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online