There are a wide variety of testing tools and test frameworks for automating the testing of Java/J2EE applications and server components. Many are aimed at unit or functional testing, while others are utilized for specific types of Java components such as view, logic and validation components.
JUnit is perhaps the best known testing framework from which other frameworks are derived. It is useful in test-driven development methodologies. JUnit links into an application as a JAR. It possesses several valuable features such as annotation and assertions. Due to its simplicity, unit tests are run quickly with instant results via a red/green progress bar.
JWalk is another unit testing tool for Java that supports a specific test paradigm known as Lazy Systematic Unit Testing. Tests are run using the JWalkTester tool on any compiled Java class. It supports “lazy specifications,” dynamic and static code analysis, plus insertion of programmer hints.
TestNG is another JUnit-derived framework used for unit, functional and integration testing. It is growing in popularity compared to JUnit due to a number of extra features such as annotations, parameters, embedding BeanShell, flexible test configurations and the ability to test if code is multithread safe.
JWebUnit is a meta-framework that wraps other frameworks such as HTMLUnit or Selenium for use in functional, integration and regression testing of Java applications. It provides a single, simple interface for test case writing. It is also useful for screen navigation testing.
Java Test Frameworks
In addition to the test frameworks above, there are other component-specific frameworks that are popular for test automation.
For JQuery testing, QUnit is perhaps the most popular tool in use due to its simplicity and easily understood screen display. It has no dependencies on jQuery but supports all the browsers that jQuery 1.x does including IE, Chrome, Firefox, Opera and Safari.
Java Server Page Testing
TagUnit is similar in use to JUnit. It also has test cases, test suites and tests that are written as assertions. However, tests are written as JSP pages instead of Java classes. Each assertion is a custom tag. A single test is a collection of tags within a page. For a given tag, all the tests associated with that tag make up a test case. Tag classes are called when the JSP is converted to a Servlet.
Java Virtual Machine Testing
The most innovative and extensible framework for JVM testing is Arquillian. It is used by developers for rapid creation of automated functional, integration and acceptance Java tests. Tests are run directly from the run-time by managing the entire container life cycle and bundling all relevant test cases plus class and resource dependencies. It integrates with other frameworks such as TestNG, Junit and HTMLUnit.
Java Web Application Testing
Selenium WebDriver is an official W3C specification that provides a method for direct web browser interaction in the same way that humans do via a hook supplied by popular browser developers. It can simulate all user web actions.
HTMLUnit is another open source, headless browser testing tool. It is mainly used for integration testing via JSPs that run inside its web container and are converted to Servlets. Even without the container, however, it can be used to test the View portion of the application.
Other Useful Java Testing Tools
XMLUnit is JUnit extension for validating XML structure and performing content comparisons between actual and expected XML. It also shows the result of transforming XML with XSLT and XPath expression evaluations relative to specific portions of XML.
Apache JMeter is a valuable tool for testing website performance by means of sending multiple requests and displaying behavior graphically based on statistical analysis. It works over a large number of protocols including HTTP, HTTPS, SOAP/REST, FTP, LDAP, SMTP, MongoDB and others.
Java developers have a large number of testing tools and frameworks available to them of which we have briefly discussed the most popular and useful instances. These tools are used to automate testing throughout the entire software lifecycle from development to deployment.