Java Testing Complete Guide
Java Testing Complete Guide
In this article, we discuss nine of the most common types of application testing and review code samples and tools for each in Java.
Join the DZone community and get the full member experience.Join For Free
The best way to write a good application is to cover it with the right tests. In this article, I describe the majority of existing testing types. All examples will be implemented with Java.
Unit testing verifies that each application function (module) returns the correct value for a given input. By counting all lines executed during the test, you can find your code coverage. Code coverage is still one of the most important code quality metrics.
Mutation testing is a way to find a missing tests in your code. The main idea of mutation testing says: once all unit test are written, every change in your code should fail at least of the existent unit tests. Otherwise, you have one missing test.
The main purpose of integration testing is to check the compatibility and consistency of a group of modules or a whole application. Depending on the application container, different frameworks are used.
You may also like: Automated Testing: Improving Application Speed and Quality.
Most of the application has some user interface. It might be web page or desktop frame. Java frameworks provide both (eg: javafx and vaadin). User interface testing often plays a role of end to end testing. I think UI testing is the most effective in terms of time and quality assurance.
Java support hundreds of different protols: TCP/IP, HTTP, SOAP, UDP, FTP, SMTP, etc. In this example, I'll use HTTP, as it's the most popular protocol.
Java HTTP tests frameworks: spring.
Server test example:
The best way to precisely measure your code's efficiency is to use benchmark frameworks. Benchmark test give you very fair code execution results, ignoring possible side effects (e.g. warm-up stages).
To find out what load your application can withstand, you need to use performance testing tools (also known as stress testing tools). Performance measures depend on the protocol used, but there are already tools that support most popular protocols.
Performance application (might be integrated with Java): Jmeter.
To find out how vulnerable an app is, you can use security test solutions. Security testing also depends on protocols of your application. But, often, security tool cover the most known use cases, like SQL injection or XSS injection.
Security tool: Arachni Scanner.
In most cases, database are a large part of an application. A database can be tested in many ways: schema check, security check, performance, etc.
Java database test engine: DbUnit.
New ways to test applications are growing every day and so are the number of technologies used to perform tests, but this list of nine types of testing should be useful for quite long time.
Opinions expressed by DZone contributors are their own.