DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Java 2021: What Frameworks and Trends for This New Year?
  • Build a Full Stack App With SvelteKit and OceanBase
  • Java Module Benefits With Example
  • Providing Enum Consistency Between Application and Data

Trending

  • Unlocking Smart Meter Insights with Smart Datastream
  • Navigating the Complexities of AI-Driven Integration in Multi-Cloud Environments: A Veteran’s Insights
  • Setting Up a Data Catalog With Azure Purview and Collibra: What Three Attempts Taught Me
  • Programmatic Brand Extraction: Pulling Logos, Colors, and Assets from Any URL
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Java Testing Complete Guide

Java Testing Complete Guide

By 
Dmitry Egorov user avatar
Dmitry Egorov
DZone Core CORE ·
Updated Mar. 11, 20 · Tutorial
Likes (38)
Comment
Save
Tweet
Share
58.9K Views

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

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.

Possible Java unit testing frameworks: JUnit, TestNG . 

Test example:

Unit testing example

Unit testing example

Mutation Testing

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.

Java mutation frameworks: Pitest. More details about PITEST with examples. 

Test example:

Mutation test example

Mutation test example

Integration Testing

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.

Java integration frameworks (container-independent): Mockito, PowerMock.

 Test example:

Integration test

Integration test example

UI Testing

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 UI testing for web: selenium for desktop: Winium

Test example:

UI Testing

UI Testing example

Protocol Testing

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:

Protocol testing example

Protocol testing example

Benchmark Testing

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). 

Java benchmark framework: JMH. More details in this article.

Code example: 

Benchmark testing example

Benchmark testing example

Performance Testing

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.

Test example:

Performance testing example

Performance testing example

Security Testing

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.

Script example:

Vulnerability testing example

Vulnerability testing example

Database Testing

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.

Test example:

Database testing example

Database testing example

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. 


Further Reading

  • Mutation Testing: Covering Your Code With the Right Test Cases (Part 2).
Java (programming language) unit test application Security testing Database Framework

Opinions expressed by DZone contributors are their own.

Related

  • Java 2021: What Frameworks and Trends for This New Year?
  • Build a Full Stack App With SvelteKit and OceanBase
  • Java Module Benefits With Example
  • Providing Enum Consistency Between Application and Data

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook