Most programmers spend a lot of time debugging Java code. For most of us, it is not a complex task, but writing test cases manually is a time consuming process. Fortunately, there are many automated testing tools and frameworks that can significantly improve the workflow of Java development.
Why Automated Testing?
When you release an untested product in a production environment, the reviews you will get might not be fruitful. The best idea is to apply a testing phase on your software. These testing code should be written before the software code. This is to ensure that the application code we have written works properly.
Manual testing can be replaced with automated testing to save time and avoid repetitive task. Automated testing is a technique where we use 3rd party software to execute test, report outputs and compare final results. These automated tools allow us to spend more time creating the logic of testing code.
Mockito allows developers to create and test double objects (mock objects) in automated unit tests. The tests are well documented and they produce clean verification errors. Mockito library enables mocks creation, verification and stubbing. You’ll need to declare a dependency on “mockito-core” library using your favorite build system.
Concutest is a framework for testing concurrent Java programs, freely available under the BSD License. It includes ConcJunit (an extension for JUnit framework), Thread checker (a lightweight annotation language) and Schedule based execution (for executing unit tests based on specified records).
EasyMock provides an easy way to use Mock objects in unit testing. It provides mock objects by creating them on the fly using Java proxy mechanism. To test a unit in isolation or mount a sufficient environment, EasyMock simulates the collaborators in the test.
Before getting started, you need to add EasyMock dependency to your POM file and then, add class to test and a collaborator (can be a class or an interface) used by this class.
Concordion is an acceptance testing framework, inspired by Fit framework. All tests are written in HTML and then instrumented with special parameters to run the test. You can write them in normal language, tables and proper punctuation.
The HTML files are usually stored with application code which allows the developers to have complete control over all test cases. The tool enriches agile processes and has been successfully implemented in industrial context.
Powermock is a framework that extends other mock libraries like EasyMock and Mockito with more powerful capabilities. It is packed with several features that simplifies reflection specifically used for testing. It uses a custom classloader and bytecode manipulation to enable mocking of constructors, static methods, final classes and more.
It is primarily designed to extend the existing API’s with a small number of methods. There are two APIs: one for EasyMock and one for Mockito. You need to depend on one of these APIs as well as test framework. Please avoid this tool if you are not an expert in unit testing. For newbies, this may cause more harm than good.
JUnit is a unit testing framework developed for Java programming language. It is one of a family of xUnit originated with SUnit. It is linked as a JAR at compile time and can be used to write repeatable tests.
There is a set of rules that allows flexible addition or redefinition of the behavior of each test method in a test class. You can write tests for projects related to scientific experiments using randomly generated data. Moreover, you can group your test together for easier test filtering.
Yet another unit testing toolkit designed to support a testing mechanism called Lazy Systematic Unit Testing. The JWalk tools propose all the significant test cases systematically, predict outcomes for many more test cases and generate new tests after a class’s configuration has changed.
The software consists of many tools including JWalktester, JWalker test engine, CustomGenerator, JWalkEditor, JWalkUtility and JWalkMarker. You’ll need a valid JWalk license (an electronic certificate, free of charge) to run the software.
Cactus is a unit testing framework for server-side Java code such as Servlets, EJBs, Filters. The aim is to lower the cost of writing tests for server-side code using JUnit framework. Cactus implements an in-container strategy (tests are executed inside the container) and supports testing for View layer through integration with HttpUnit. Moreover, it provides a good middle ground in term of test granularity. The tool is not being updated anymore.
Abbot helps you test your Java UI. It consists of Costello (script editor) which allows you to easily launch, explore and control an application. You can use this framework with both scripts and compile code.
Costello can record user actions and facilitate script construction and maintenance. It provides a hierarchy browser which displays all components in use by the program code, as well as meta data about any component selected in the hierarchy.
Jameleon is extensible, data-driven automated testing framework that can be easily used by non-technical users. It separates application into features and allows those features to be tied together independently, creating test cases. These cases are then used to automate testing and to generate manual test case documentation.
The tool is broken up into different layers that can be learned by people having different skills. And because it is based on Java and XML, there is no need to learn a proprietary technology.
TestNG is a Java testing framework inspired by NUnit and JUnit. Like other tools, it supports unit, functional, end-to-end and integration testing. You can use it in Eclipse, IDEA, Selenium, Maven and Ant.
There are some functionalities that make it more powerful and easier to use, such as running tests in arbitrarily big thread pools, code testing in a multi thread safe, flexible test configuration, dependent methods for application server testing, support for data-driven testing and parameters, and more.
Marathon is a GUI testing tool for Java/Swing applications. It comes with a recorder, runner and editor. The test scripts can be in Ruby or Python code. The aim is to produce test scripts that are readable by everyone on the project.
Marathon has some great features that make it different from other testing framework – integrated debugger and script console, powerful object recognition, batch runner for unattended execution of test scripts, extract-method refactoring, resilient test suites, application launcher to test your source code, and more.
3. The Grinder
The Grinder makes it easy to run a distributed test using several load injector machines. All test scripts are written using a dynamic scripting language. The default language is Jython (Java implementation of Python).
It can test anything that contains Java API such as HTTP web servers, SOAP and REST web services, application servers and custom protocols. The mature HTTP supports automatic connection of client, cookies, SSL and connection throttling. Also, the graphical console allows multiple load injectors to be monitored and controlled.
2. Parasoft Jtest
Parasoft Jtest is a static analysis tool and automated testing software that can be used for unit-test case generation and execution, regression testing and detection run-time error. The software is used by many big companies including Cisco Systems and Wipro Technologies.
The static analysis automatically checks the code against hundreds of custom rules in order to eliminate entire class of programming errors. Currently, it supports Eclipse IDE, Maven, Ant, CruiseControl and IBM Rational Application Developer.
Arquillian is an extensible testing platform for JVM that lets you easily create automated integration, functional and acceptance tests. You can test in run-time, and even run your Arquillian tests right alongside unit tests in your IDE. Your software and tests can share the same programming model, regardless of technology stack.
You can just drop a breakpoint in the test or software code and debug the test. You name the container, Arquillian will manage it by bundling test cases, deploying archives, executing tests in the containers, capturing results and creating reports.