90 likes | 207 Views
D. and P. D. is a dynamite programmer. Always finishes programs before the rest of the class Has an easy time with even the hardest program P. has a tough time with this class Takes longer than other students to finish programs Finds it hard to figure out how to get the program to work.
E N D
D. and P. • D. is a dynamite programmer. • Always finishes programs before the rest of the class • Has an easy time with even the hardest program • P. has a tough time with this class • Takes longer than other students to finish programs • Finds it hard to figure out how to get the program to work. • Why does P. always get A’s while D. doesn’t? • Why will P. become a successful software engineer, while D. keeps losing jobs?
Testing • Some programmers find writing programs easy, others take longer • But all programmers, regardless of their skill, can test their software • That’s because testing is mostly ATTITUDE
Testing Attitude • Understand that testing is vital for creating a correct program • Any programmers can produce great programs if they test them thoroughly and don’t deliver them until they’re 100% correct • Even the best programmer will be EMBARRASSED often if testing is not thorough. • No matter how good you are, assume your program is total crap until you’ve proven to yourself that it works in every possible case!
In Short… • Assume a CLOWN wrote your computer program! • Your job is to fix it so it works. • To do that, you need to figure out what’s wrong
The Alternative • Assume your program works • Test it a little because you have to • Prepare to be embarrassed
Some Tips • Never delete a test driver or input tests from the console • Keep your tests around • You will need them if you make changes • Rerun your test driver if you make the slightest change • Test based on what your method DOES not on what’s happening inside
Example, test our average program public static double average (double a, double b, double c){ double d = a + b + c; double e = d / 3; return d; }
Never, never, never do this public static double average (double a, double b, double c){ double d = a + b + c; double e = d / 3; System.out.println(e); return d; } • In your main: double a = average (3.0,4.0,5.0); • Prints 4.0. Program must work
Instead: public static double average (double a, double b, double c){ double d = a + b + c; double e = d / 3; return d; } • In your main: double a = average (3.0,4.0,5.0); System.out.println(a); • Prints 12.0. Program didn’t work after all