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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Java 2021: What Frameworks and Trends for This New Year?
  • Micronaut With Relation Database and...Tests
  • Modern Cloud-Native Jakarta EE Frameworks: Tips, Challenges, and Trends.
  • Build a Full Stack App With SvelteKit and OceanBase

Trending

  • Simpler Data Transfer Objects With Java Records
  • AI Agents: A New Era for Integration Professionals
  • Implementing Explainable AI in CRM Using Stream Processing
  • How to Introduce a New API Quickly Using Micronaut
  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.5K 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?
  • Micronaut With Relation Database and...Tests
  • Modern Cloud-Native Jakarta EE Frameworks: Tips, Challenges, and Trends.
  • Build a Full Stack App With SvelteKit and OceanBase

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!