How to Test JAVA Applications – Tips with Sample Test Cases (Part 1)

In this tutorial, we will learn the components involved in a Java application and the various types of testing that need to be carried out to ensure a high quality, bug-free application.

This is a three-part series on testing JAVA applications.

  1. In this article, we will learn the J2EE components and Manual testing approach for a J2EE application.
  2. In the second, we will review the Automated testing approach for testing J2EE applications, and
  3. In the third, we will review a comprehensive list of tools that are available for testing J2EE applications.

What You Will Learn:

Let’s Start With Overview of J2EE Applications

A Java web application consists of several components, each serving an important purpose. MVC, which stands for Model View Controller, stands as the most popular and frequently used Architectural design pattern.

Before learning to test, let us briefly go through the various components of a J2EE application.

Please note that not all web applications follow the JSP -> Servlet -> EJB -> Database model. Most of the J2EE applications are currently written with a framework such as Struts, Spring, or Hibernate. The design of applications varies for each requirement based on a size of the application, cost, development time, resources and team size.

Testing JAVA/J2EE Application

Let us now move to testing an entire J2EE application. This is done in several steps. For example, consider that we have three screens:

The UI (User Interface) for these three screens are developed with JSP/HTML and the validations performed through JavaScript. Because it is a sample application, logic is in the Servlet and DAO (Data Access Object). DAO is a class for connecting to the database.

Below are the sample screens:

Manual Java Application Testing:

During manual JAVA testing, a tester prepares the test cases from the detailed design document and tries to cover every scenario and code snippet possible.


Unit testing is a type of testing wherein a user needs to test the smallest of the code snippets for accuracy, correctness and meeting the requirements.

Let us take the example of the login screen. The login screen has two text fields: username and password, and has two buttons: submit and cancel.

The test cases should cover all the loops and conditional statements. Test cases should display the expected results and the test data. Below are some of the general test cases that a user could execute manually in a login screen. The results are then noted down in the test case document.

Below is a sample test case format for the login screen.

S.No.Test CaseExpected ResultActual ResultPass/Fail
1User checks the appearance of labels Username, PasswordThe labels should be correctly spelled and displayed in Normal sized fontThe label username and password are displayed correctlyPASS
2User checks the appearance of the button

Submit and Cancel
The buttons should be displayed with the correct nameThe buttons Submit and Cancel are displayed correctlyPASS
3User checks the background color of the screenThe login form should be within a white table and the screen should be of background greyThe screen appearance does not match the requirements.FAIL
4The user leaves username textbox as BlankError message “Username cannot be empty” should be displayedError message “Username cannot be empty” is displayedPASS
5The user enters some value in the username textbox and leave the password textbox as BlankError message “Password cannot be empty” should be displayedError message “Password cannot be empty” is displayedPASS
6User enters username as “abcd” and password as “xxxx”Error message

“Invalid username password combination”

should be displayed
Error message

“Invalid username password combination”

is displayed
4User enters a username of more than 10 charactersError message

“Username should not be more than 10 characters” should be displayed
Error message is not displayedFAIL
5User enters username as “testuser” and password as “password” and clicks the Submit buttonThe user should be able to see the “Employee details screen”Employee details screen is displayedPASS

While table lists some of the test cases, below is the complete list:

After going through the test cases, you may realize that you are mostly dealing with the testing of fields, buttons, functionality, and validations of a particular screen. This is accurate, as Unit Testing very keenly deals with the testing of every small code snippet and component. The same type of testing should be performed for all the screens.

Please note that the above are examples only, and test cases are prepared based on a project-specific and detailed design document.

Read Also => Sample ready to use test cases and test scenarios for web application testing.


In Integration testing, individual modules are integrated and tested together for correctness.

Let each of the three screens in the above example is developed by three different team members. Now that they are finished with Unit testing, it is time to bring all the code together and check if they work well together. Integration testing is performed to ensure that data or control is transferred correctly from one screen to another.

Here are some sample integration test cases for the Employee Application example:

In addition, the general integration test cases for a J2EE application could be:


In System testing, the entire application is tested for functionality and completeness with respect to the requirements. It would likely be easier to ask when Unit testing of every component is performed and the code components are also combined and tested together during integration testing, what could be different in System testing? It is not inaccurate to say that the idea in System Testing is to break the application :)

Scenario #1: You develop a new employee application with a framework; for example, Struts. There are also several other applications running on different servers in your organization. However, all of them call the same existing web service to fetch the address and phone number for any particular person.

During integration testing, you would have tested if your application is able to make a call to the web service and if you are able to get the response. But what if there is a problem in the web service itself? Or the web service does not respond to some rare inputs? The web service, in our case, can only take an employee number max of 6 characters. Or, the web service throws exceptions for certain formats of address while returning. This is external, but it also part of System testing.

Scenario #2: Your employee application is complete. You add an employee, and it generates an Employee Number #1001. You modify, delete, update, add, modify, delete, add, add, add, modify, delete and then finally add another. What if the new employee number is again #1001?

Scenario #3: Let us assume two users are using the application at the same time. Both of them start working on the same employee, one deletes. What if the other user is able to proceed with the modification of same employees as it is stored in the session?

Below are some important aspects of System testing:


This type of testing is performed when there would be a large number of users using the application or large amount data in the database, or both. Below are some of the cases:


In this article, we have covered an overview of a J2EE application. We have also seen how to manually perform Unit, Integration, Functional and System testing for each of the components of the application with an example.

In the next article, we will see the how Automation testing can be beneficial for large J2EE applications.

About Author: This is a guest article by Padmavaty S. With overall 7+ years of software testing experience she is having extensive experience in testing Java, J2EE, MVC, and Struts framework.

Let us know if you are working on testing JAVA applications. Share your experience and queries in comments below.