Reputation: 73
We have been assigned an open source software to test! The software has 3 packages and each package has 10 or more classes and each class might have dozens of methods.
My question is that before I start structural (white-box) testing, do i need to understand every line of code in the software?
Do I need to understand the whole flow of program starting from main() method?
What is the approach I should take?
Upvotes: 0
Views: 119
Reputation: 1980
There are several types of tests.
BigInteger fact(int n)
method, you have to write tests on normal positive integers, zero, negative integers and max/min values. There are several libraries which'll help you: JUnit,TestNG, etc. After dark ages of software industry the community finally came to some good unit testing practices:
Upvotes: 0
Reputation: 381
No, you don't have to understand every line of code to write Unit tests. I'm not so experienced with unit tests yet, but what if seen so far is testing every (or most) methods that respond differently to a certain input (--> arguments, object variables ...).
So you have to know what a method does, when it successfully does things, and when it is suppose to fail. And for some methods even the turning points between those cases are important.
For Example
Let's say we have a method that sums two ints, that have to be equal to or larger than 0:
public static int sumInts(int a, int b) {
if (a < 0 || b < 0) throw new IllegalArgumentException("'a' and 'b' should be 0 or above!");
return a + b;
}
What you could test:
Of course, this is just a very simple example. What you test depends on your method. For this method, the last two tests would likely be totally unneeded. But there are methods that are more complex, where those could be useful.
Upvotes: 0
Reputation: 2013
If you have specs on what each method is supposed to do: What is expected output for specified input then no you don't need to go into implementation details of those methods. Normally this should be written down!
You could write unit tests that check if methods are satisfying predefined contracts (if they exist).
If you don't have specs or with recent trend 'UserStories' you need to 'reverse engineer your specs' :) You would need to analyse each method to understand what is it doing, next you will check where those methods are being called in order to figure out what are the possible values passed in the method calls. Also from the calling methods you might get the idea what are the corner cases. And those you definitely want to test.
.... and slowly you learned the whole code :)
Upvotes: 2