I do not understand what exactly does the unit tests test?
eg.
public class Z{
public static void main(String[] args){
int a,b,c;
a=0;
b=20;
c=10;
a=(b*b - c)/c;
System.out.println("The value of a is "+a);
}
}
Now what the unit test will test in above class?
What is unit testing?
The point of unit testing as I understand it is to make small units, that are easily tested, and the program is combined of these small units (in different ways).
You unit test above seems to test the statement a = ( b * b - c ) / c
then, of course, prints the result of 39 out.
For further testing of class Z, you would need to change the values of a, b, and c. This would probably be best done with a text file, containing the data for a, b, and c, inputted at the command line (in various different ways), but this is another story (question/answer).
Reply:To unit test this piece of code you need to come up with values for a, b, and c which will cover the following:
1. typical cases
2. boundary conditions
3. error cases
For example, b = 20, c = 10 is a typical case. However, b = 20, c = 0 would be an error case.
Reply:you wrote, "what is unit testing?".
unit testing is simply testing parts or "units" of your program. these units often correspond to methods or functions. in this case you are unit testing the "main" method of the class "Z".
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment