Backend Handbook
Leapwise
  • 👋Introduction
  • Software Design Principles & Clean Code
    • Atomicity
    • Modularity
    • Hierarchy
    • Loose coupling
    • Asynchronous programming
  • Development Practices
    • JavaDocs
    • Technical Debt
    • Testing Guidelines
      • The Importance of Test Automation
      • The Testing Pyramid
        • Unit Tests
        • Integration Tests
        • End-to-End Tests
      • Mutation Testing
      • Contract Tests
        • REST Controller Contract testing
        • OpenAPI Contract testing
      • Testing Frameworks
        • JUnit 5
        • Testcontainers
        • Mockito
      • Writing Clean Tests - Best Practices
    • Common library
    • Generic CRUD
    • Update Facade
  • Development Tools & Environment
    • Monitoring
    • Performance tuning
    • Multi-tenancy & Configuration Management
    • Git practices
    • CI/CD
    • Maven
  • Project Management
    • Jira
    • Confluence documentation
    • SCRUM
    • Our ways of working
  • LIFE AT LEAPWISE
    • Introduction
    • Who are we?
    • What do we do?
    • Our values
    • Hiring process
      • Hiring: A Mid Frontend Developer's Point of View
    • Benefits we offer
    • Onboarding process
      • Onboarding: A Senior Digital Marketing Specialist's perspective
    • Mentorship program
    • Career development
      • Trainings & certificates we offer
      • Career development: A Senior Software Developer's Insight
    • Community building
    • Juniorship
    • First-hand info from our first team member
    • Join our team
Powered by GitBook
LogoLogo

Company

  • About
  • Culture
  • Services

Insights

  • Leapwise Newsletter
  • Blog

© Leapwise

On this page
  • About
  • Glossary
  • Code coverage
  • Coverage runner in IntelliJ
  • Types of Mutation Testing
  • PIT

Was this helpful?

  1. Development Practices
  2. Testing Guidelines

Mutation Testing

PreviousEnd-to-End TestsNextContract Tests

Last updated 11 months ago

Was this helpful?

About

Mutation testing assesses software test quality by adding small code defects and checking if tests can find them. It measures how well tests identify errors, aiming for a high mutation detection rate for a strong test suite.

A mutation is nothing but a single syntactic change made in the code. Each mutant code should differ from the original code by one mutation.

Glossary

Code coverage

Code coverage is a false indicator of protection. Good coverage does not imply good tests. It is important to distinguish line and branch test coverage:

  • Line Coverage - the percent of lines executed by this test run

  • Branch Coverage - the percent of branches executed by this test run

Example:

public int getNameLength(boolean isAdminUser) {
    User user = null;
    if (isAdminUser) {
        user = new John();
    }
    return user.getName().length();
}
  • if we call the getNameLength method with isAdminUser set to true, we will get 100% line coverage

  • branch coverage is 50% - we can see there is something missing in our testing

  • NullPointerException in case isAdminUser flag is false

Coverage runner in IntelliJ

IntelliJ's Coverage runner allows you to switch from default Line Coverage to JaCoCo for collecting Branch Coverage.

Types of Mutation Testing

Mutation testing is categorised into 3 types:

  • statement mutation – developer cut and pastes a part of a code of which the outcome may be a removal of some lines

  • value mutation – values of primary parameters are modified

  • decision mutation – control statements are to be changed

What should be changed in Mutant Program?

  • operand replacement

    • replace the operand with another operand or with the constant value

    • if(x>y) replace x and y values

  • expression Modification

    • replace an operator or insert a new operator in a statement

    • if(x==y) replace == with >=

  • statement modification

    • statements are modified to create mutant programs

    • delete the else part in an if-else statement

    • delete the entire if-else statement to check how a program behaves

PIT

PIT mutation testing runs unit tests against automatically modified code, providing a Mutation Coverage metric. It is fast, easy to use (e.g., Maven, Gradle), actively developed, and supported. The reports from PIT combine line and mutation coverage information.

mutant

a unit modification of the code (e.g: != replaced by ==)

killed/captured

a mutant was killed if the unit test fails (positive outcome)

lived/escaped

a mutant escapes if the unit test doesn’t fail (negative outcome)

uncovered

a mutant is uncovered if no test covers the mutated code

Page cover image