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

  • Modern Test Automation With AI (LLM) and Playwright MCP
  • AI-Driven Test Automation Techniques for Multimodal Systems
  • Debugging With Confidence in the Age of Observability-First Systems
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization

Trending

  • Apple and Anthropic Partner on AI-Powered Vibe-Coding Tool – Public Release TBD
  • The End of “Good Enough Agile”
  • Creating a Web Project: Caching for Performance Optimization
  • Modern Test Automation With AI (LLM) and Playwright MCP
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Mutation Testing: Covering Your Code With the Right Test Cases (Part 2)

Mutation Testing: Covering Your Code With the Right Test Cases (Part 2)

Check out our second installment on how to mutate code and obtain quality code coverage.

By 
Dmitry Egorov user avatar
Dmitry Egorov
DZone Core CORE ·
Updated Jun. 10, 20 · Tutorial
Likes (22)
Comment
Save
Tweet
Share
38.4K Views

Join the DZone community and get the full member experience.

Join For Free

Image title

In part one, we achieved 100 percent coverage. In this installment, we mutate our code and check how good our tests are.

There are several mutation testing frameworks. In this case, we will use PITEST.

Image title

What mutation might be applied to the code? Here is a list of pitest mutations here:

Image title


Let me introduce our mutants (just few of them). First is the line of origin, and the following are mutants (modified code is highlighed by red):Image title

Image title


Now, let's execute the pitest Maven plugin and check the mutation testing result:

mvn clean test

mvn org.pitest:pitest-maven:mutationCoverage


Open report located in target/pit-reports/201902032155/index.html

Image title


So, the report says:

  1. Line coverage 100 percent, but we knew it from the JoCoCo report earlier
  2. There are two mutation that survived and 23 were killed.
  3. Mutant 1 was created by changing conditional boundary at line 14 and the second by replacing return with true.

Let's clarify what mutants looks like:

Image title


So, what are the missing test cases that might eliminate our mutants?

  1. For our first mutant, we create a boundary case and assert that the client is created as far as zero passport id is valid
  2. For the second mutant, we check that the service doesn't have an unexistent client.

Image title


Results give us 100 percent killed mutants, but can we rely on it?

Unfortunately not. Mutation testing gives us just some hints —what cases we might forget (especially for boundary conditions).If we count all possible application set of states, we found out there are more "missing" cases.

Criticism of Mutation Testing

  • Time-consuming. Due big number of execution: number of mutations * number of tests
  • Creates impression of fully tested app if no mutations been found 
  • Don't provide clear metrics of test quality 

Conclusion

  • Mutation testing helps us to find possible missing test cases
  • Mutation testing can't find all missing test

Lastly, I didn't describe a case when mutation can be equivalent to the initial code, but it does not happen that often.

Code used in this article is available on GitHub.

Testing

Opinions expressed by DZone contributors are their own.

Related

  • Modern Test Automation With AI (LLM) and Playwright MCP
  • AI-Driven Test Automation Techniques for Multimodal Systems
  • Debugging With Confidence in the Age of Observability-First Systems
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization

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!