Thursday, November 1, 2012

Test a program that outputs factorial of a number

Given a simple program designed to take inputs of integers from 1-1000 and to output the factorial value of that number, how would you test this program? You do not have access to the code

Strategy:
This is a standard testing question. In professional world when you are testing anything, you are expected to automate the entire process. So in this case they do not expect you to check the factorial value returned each time. Rather first you have to write a routine that gives the correct factorial value for numbers between 1-1000. (There are no efficiency constraints)
Now you need to check for different test cases such as
1) It must return the correct value for the numbers in the range. You do not need to check for each number but can randomly pick 100 numbers (or whatever with the interviewer would be satisfied) from 1-1000 and check for them.
2) Then you must check what it gives for values out of the range and if it crashes or not.
3) You should also check for negative numbers and floating point. In all the cases the code should reject the input and not crash.

Try to think of as many as possible such test cases. Testing questions are an integral part of interviews because even if you are being selected for a Dev profile, you need to test your code thoroughly.
While answering testing questions you should be imaginative and speak out whatever weird condition/check that comes to your mind. They are testing you for your thoroughness and the understanding of what actually that code does.

No comments:

Post a Comment