Coder Social home page Coder Social logo

course-service's Introduction

Unit, Integration and Mutation Testing Project

Overview

This project is a Spring Boot application that manages courses. It provides RESTful HTTP services for handling Course entities.

Testing Overview

Unit Testing

Unit Testing involves testing individual components of a software application in isolation to ensure they work as expected. These tests are typically written by developers and run frequently to catch bugs early in the development cycle.

Benefits of Unit Testing:

  • Identifies issues early in the development process.
  • Provides documentation for the code.
  • Facilitates changes and simplifies integration.

Integration Testing

Integration Testing involves testing the interactions between different components or modules of an application to ensure they work together correctly. These tests are typically more extensive than unit tests and may involve a real or simulated environment.

Benefits of Integration Testing:

  • Validates the interaction between integrated components.
  • Detects interface issues between modules.
  • Provides end-to-end testing scenarios.

End-to-End (E2E) Testing

End-to-End (E2E) Testing involves testing the entire application flow from start to finish to ensure that the system as a whole works as expected. These tests simulate real user scenarios and validate that the system meets the requirements.

Benefits of E2E Testing:

  • Validates the entire application workflow.
  • Ensures that the system meets business requirements.
  • Detects issues that may not be found in unit or integration tests.

The Testing Pyramid

The Testing Pyramid is a conceptual framework that highlights the different levels of testing required for a robust software application. It emphasizes having a large number of unit tests, fewer integration tests, and even fewer end-to-end tests.

alt

Explanation of the Testing Pyramid:

Unit Tests: Form the base of the pyramid. They are fast, numerous, and provide a solid foundation by testing individual components in isolation.

Characteristics of a good unit test

Fast: It isn't uncommon for mature projects to have thousands of unit tests. Unit tests should take little time to run. Milliseconds.

Isolated: Unit tests are standalone, can be run in isolation, and have no dependencies on any outside factors such as a file system or database.

Repeatable: Running a unit test should be consistent with its results, that is, it always returns the same result if you don't change anything in between runs.

Self-Checking: The test should be able to automatically detect if it passed or failed without any human interaction.

Timely: A unit test shouldn't take a disproportionately long time to write compared to the code being tested. If you find testing the code taking a large amount of time compared to writing the code, consider a design that is more testable.

Integration Tests: Make up the middle layer. They test the interactions between components and are fewer in number compared to unit tests.

End-to-End Tests: Sit at the top of the pyramid. They test the application as a whole, from the user interface to the data layer. These tests are fewer because they are slower and more complex to maintain.

Steps for this exercice

1. Execute and test the app

  • a. Run the App:

Get all tags, just in case.

git fetch --all --tags

Select the first one:

git checkout tags/step-1-initial-setup

And now continue:

./mvnw clean install -U

./mvnw spring-boot:run

  • b. See the results with Postman:

alt

alt

2. Run the Unit Tests with Jacoco coverage

  • a. Run the tests and coverage:

./mvnw clean test jacoco:report

-b. See the Jacoco Report: alt

Nothing about service layer, and the Controller doesn't test the NotFound:

alt

3. Run the Integration Tests with Jacoco coverage

  • a. Run tests with verify, where Integration tests are included and Unit don't

./mvnw clean verify jacoco:report

-b. Results of Jacoco: alt

Coverage 100%, including service...but it is just Integration Tests.

4. Improve Unit Tests

  • a. Get the second step Tag:

git checkout tags/step-2-basic-functionality

  • b. Run the tests and coverage:

./mvnw clean test jacoco:report

  • c. See the Jacoco Report: alt

Now we have 100% coverage!

5. Execute Mutation Tests

  • a. Execute mutation tests:

./mvnw org.pitest:pitest-maven:mutationCoverage

  • b. Result of the Mutation:

alt alt

We can try this, just by commenting the 44 and 45 lines of the CourseController, and the tests will be ok!, as if it were fine.

6. Improve Unit Tests

  • a. Get the final code:

git checkout main

  • b. Run the latest step from main:

./mvnw clean test jacoco:report

  • c. Execute mutation tests:

./mvnw org.pitest:pitest-maven:mutationCoverage

  • d. Result of the Mutation:

alt

course-service's People

Contributors

diegochavezcarro avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.