For the simple test method above, any failure can be understood by the tester easily without the help of printstacktrace.
There are some failures that are hard to debug. For example, suppose we pass three parameters to a test method. We failed to implement session maintenance for one of the 3 objects passed as parameters and it happens to be passed as null as a consequence. Such failures are hard to debug. It can be easily narrowed down to the root cause using stacktrace.
For example let's take a sample test case to first login into facebook and then add a friend. Suppose login code is written as a separate file for re-usability under the same namespace. First I call the login module in the test case and then call the add-friend module. When I run the test case the user logs into facebook, and fails at the add-friend module call because I missed to maintain the session of the selenium object. When the call is returned from the login module, it doesn't know that the user has already logged in since the selenium object is null. When I try to add-friend it throws an exception. The root cause of this exception can be traced more easily with printstacktrace.
/Test Case Code/
package resources.module;
public class addFriend
{
//To set the baseURL and server port
DefaultSelenium sel = new DefaultSelenium("localhost", 4444, "*firefox","http://facebook.com/");
//Declaration to instantiate class for reusable pieces of code written as module in /resources/modul
resources.module.loginFriend loginFacebook= new resources.module.loginFriend();
resources.module.addFriend addFbfriend = new resources.module.addFriend();
public void setUp()
{
...Starting server code
}
@Test
public void testaddFriend(DefaultSelenium sel, String user1, String pass1, String user2, String pass2)
{
loginFacebook(sel, user1, pass1); //User1 logs into facebook by calling login module
addFbfriend(sel, user1, pass1, user2, pass2) //User1 adds User2 as friend
}
Now lets see the login module code
package resources.module;
public class loginFriend
{
@Test
public void loginFb(DefaultSelenium sel, String username, String password)
{
Code to login
}
}
Now lets see the addfriend module which throws exception
package resources.module;
public class addFriend
{
public void addFbfriend(DefaultSelenium sel, String user1, String pass1, String user2, String pass2)
{
sel.click("link=Profile"); //throws exception since selenium object is passed as null
}
}