• About Us
    • Who We Are
    • Our Work
    • Our Clients
    • Our Partners
    • Our Blog
    • News & Events
    • Insights
  • Solutions

    Analytics & Data Management

    Big DataBusiness AnalyticsData IntegrationData Warehousing

    Digital Business Automation

    Advanced Case ManagementBusiness Rules ManagementBusiness Process ManagementRobotic Process Automation

    Connectivity & System Integration

    Agile IntegrationAPI ManagementEnterprise Service Bus

    Enterprise Content Management

    Content Capturing & ImagingEnterprise Content Management

    Enterprise Portal & Mobility

    Digital Customer ExperienceDigital Workplace

  • Industry Solutions

    • Banking >
    • Government >

    Digital Banking Transformation

    Business Process Management

    Business Rules Management

    Checks Collection & Clearing

    Counter Fraud Management

    Customer Due Diligence

    Customer Onboarding

    Daily Vouchers Management

    Debt Collections & Recovery

    Instant Payment Network Gateway

    Enterprise Content Management

    Enterprise Service Bus

    Smart Analytics

    Trade Finance Automation

    Digital Government Transformation

    Business Analytics

    Business Process Management

    Correspondence Management

    Documents & Records Management

    Enterprise Service Bus

    Pensions & Social Programs

    Social Collaboration Portal

    Strategy Management

    Utility Billing

  • Services
    • Cloud Apps & Microservices
    • IT Consultancy
    • Application Development
    • Testing Services
  • Careers
    • Careers Homepage
    • Get To Know Us
    • Engineering @ Sumerge
    • Our Culture
    • Benefits & Wellbeing
    • Job Openings
    • Graduate Programs
  • Contact Us
  • About Us
    • Who We Are
    • Our Work
    • Our Clients
    • Our Partners
    • Our Blog
    • News & Events
    • Insights
  • Solutions

    Analytics & Data Management

    Big DataBusiness AnalyticsData IntegrationData Warehousing

    Digital Business Automation

    Advanced Case ManagementBusiness Rules ManagementBusiness Process ManagementRobotic Process Automation

    Connectivity & System Integration

    Agile IntegrationAPI ManagementEnterprise Service Bus

    Enterprise Content Management

    Content Capturing & ImagingEnterprise Content Management

    Enterprise Portal & Mobility

    Digital Customer ExperienceDigital Workplace

  • Industry Solutions

    • Banking >
    • Government >

    Digital Banking Transformation

    Business Process Management

    Business Rules Management

    Checks Collection & Clearing

    Counter Fraud Management

    Customer Due Diligence

    Customer Onboarding

    Daily Vouchers Management

    Debt Collections & Recovery

    Instant Payment Network Gateway

    Enterprise Content Management

    Enterprise Service Bus

    Smart Analytics

    Trade Finance Automation

    Digital Government Transformation

    Business Analytics

    Business Process Management

    Correspondence Management

    Documents & Records Management

    Enterprise Service Bus

    Pensions & Social Programs

    Social Collaboration Portal

    Strategy Management

    Utility Billing

  • Services
    • Cloud Apps & Microservices
    • IT Consultancy
    • Application Development
    • Testing Services
  • Careers
    • Careers Homepage
    • Get To Know Us
    • Engineering @ Sumerge
    • Our Culture
    • Benefits & Wellbeing
    • Job Openings
    • Graduate Programs
  • Contact Us
Mutation Testing

Mutation Testing

  • Posted by Yomna Anwar
  • On October 25, 2021

Have you ever thought about creating unit tests with good coverage but thought that it was hard or choosing the unit test data stopped you from making the optimum tests?

If only there was a method to test my test?

What is mutation testing?

Mutation testing is a software testing type that is based on changes or mutations. Miniscule changes are introduced into the source code to check whether the defined test cases can detect errors in the code. These Miniscule changes mimic software errors so that the bugs they introduce are validated by research.
SKINNY FAT and bodybuilding, solutions to change your physique – Fitnessmith anadrol steroid health – well-being, shape, nutrition, bodybuilding, slimming advice – page 12.
The miniscule changes are Mutations

The changed source code is Mutant

 

In other words, It is A Test for Your Test.

The objective of Mutation Testing:

  • To identify pieces of code that are not tested properly.
  • To identify hidden defects that cannot be detected using other testing methods.
  • To discover new kinds of errors or bugs.
  • To assess the quality of the test cases(by calculating the mutation score).

 

Mutation Score = (killed mutants )/(total number of mutatnts ) *100

Advantages of Mutation Testing :

  • It brings a good level of error detection to the program.
  • It discovers ambiguities in the source code.
  • High coverage of the source program is attained.
  • Loopholes in test data can be identified.

Disadvantages of Mutation Testing:

  • It is highly costly and time-consuming.
  • Mutation testing is not applicable for black-box testing as it involves a lot of source code changes.

 

Note: Automation is necessary for mutation testing as it is very time-consuming.

Types of mutants & Mutations :

  • Killed mutant: mutants that were killed after mutation testing (which means that our test suit can detect changes in the code and will fail accordingly )
  • Survived mutant: mutants that are alive after running the test suit on the mutated source code.
  • Equivalent mutant: mutants that are alive even after running test data through them, but they have the same meaning as the original source code even though they may have different syntax.

Mutations:

Value Mutations:
The values are changed to detect errors in the program. Basically, a small value is changed to a larger value, or a larger value is changed to a smaller value. basically, constants are changed.

Ex : Int x = 10000000254 -> int x = 10254

 

Decision Mutations:
Logical or arithmetic operators are changed to detect errors in the program.

Ex : If (a < b)  -> if (a > b)

 

Statement Mutations:
A statement is deleted, or it is replaced by some other statements.

Ex : C = 10 -> d = 10

How to Apply Mutation Testing:

  1. Write a couple of unit tests for your module
  2. Run mutation testing automaton on it (like Pitest).
  3. Check the result and change the test suit accordingly by adding tests or changing test’s data.
  4. Repeat steps 2 and 3 until reaching good coverage.

Optional Steps:

  1. Try to remove the unit test and run the mutation testing automaton again
  2. If the coverage didn’t change Remove the test.
  3. Repeat steps 1 and 2 till you reach the optimum test suite.

Example:

In this example, we are using Pitest which Is a mutation testing system to automate the process.

Having a small function as

public int add(int a , int b){
        if(a < 2)
        {
            return (a + b)* -1;
        }
        else{

            return a+b;
       }
   }

we could start with a couple of small tests as

 public void testAdd1() {
         int result = new MutationTesting().add(0,0);
         assertEquals(0,result);
      }
 public void testAdd2() {
         int result = new MutationTesting().add(3,0);
         assertEquals(3,result);
      }

 

Then run Pitest & view the report.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Pitest created 7 mutations and our test suit killed only 3, so we can calculate the mutation score as  3/7*100 = 43%

Or we can view it in the report as the percentage next to the progress bar.

 

Mutation Testing. java

 

 

The report displays :
The number next to the line of code is the number of mutations (changes) for each line
The mutations section indicates which mutation was used on what lines and whether it survived or died.

 

The report also indicates which mutators were used

 

 

 

 

 

 

 

 

 

Note: You can find all about the available mutators and the default mutators on Pitest website https://pitest.org/quickstart/mutators/ 

 

Using the report as our guide we start to see the lack of coverage of our test suite. For example, seeing that we didn’t have a test for the edge value of 2 or we didn’t try the addition with a number other than zero to check both the branches of the “if condition”.

 

Test yourself whether you can reach the maximum coverage for this case.Feel free to contact us if you get stuck or look for the solution in here https://github.com/sandraerian16/MutationTestingExample.git

Conclusion

Mutation Testing is one of the most effective ways to ensure good coverage. It is very easy to apply and there are many mutation testing systems that help.
If you want to start making a better test suit or want to be sure of your test suit data; mutation testing is your choice, Though it might be time-consuming and costly, It would be worthwhile if done correctly.

 

 

 

 
Recent Blog Posts
  • Event Streaming: Enhancing Efficiency in Banking 
  • Your Guide To Integration Modernization
  • APIs: Transforming Chaos into Order
  • Event Streaming Simplified
  • Unlocking the Power of Spring Data JPA
Categories
  • Careers
  • Webinars
  • blog
    • Educational
  • Technology & Business
    • Digital Business Automation
    • /Modernization & Cloud Native Apps
    • Banking
    • Agile Integration
  • Software Engineering
    • Application Servers
    • Application Testing
    • Business Analysis
    • Frontend
    • Microservices
    • Uncategorized
  • Blog Posts
  • News & Events
  • Featured

Testing Flutter Apps

Previous thumb

How Project Managers can Lead Agile Practices

Next thumb
Scroll
Follow us

Significant change, positive impact and passion are our fuel. We have a unique culture reflecting the way we think and act. A culture that encourages freedom and responsibility, high performance, customer centricity and innovation.

Global Locations

Egypt

Saudi Arabia

United States

About us

Who We Are
Our Work
Our Clients
Careers
News & Events
Insights

Services

Cloud Apps & Microservices
Application Development
Consultancy
Testing Services

Solutions

Analytics & Data Management
Business Process Automation
Agile Integration
Enterprise Content Management
Enterprise Portal & Mobility

Industries

Banking
Government

Latest Blogs
  • Database Events & Triggers
    December 14, 2022
  • Design Patterns
    August 23, 2022
Copyright Ⓒ 2024 Sumerge. All rights reserved.
  • Blog
  • |
  • Support
  • |
  • Contact Us
  • |
  • Privacy Policy
Sumerge
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}

     

    Book A Free Consultation Session