Study on Continuous Integration Testing - SQA-PROJECT-1/Konta-Niben GitHub Wiki

Study on Continuous Integration Testing

Continuous Integration (CI) testing is a crucial practice in software development that ensures code quality and reliability by automating the testing process. In this document, we will explore how to implement CI testing using GitHub Actions as our CI tool in the context of our SWE group project. Our project is built using the MERN (MongoDB, Express.js, React.js, Node.js) stack, and we used Jest for unit testing.

Popular CI Tools

  • Jenkins: An open-source automation server that supports building, deploying, and automating projects.

  • Travis CI: A hosted CI service used to build and test projects hosted on GitHub and Bitbucket.

  • CircleCI: A cloud-based CI/CD platform that automates the software development process.

  • GitLab CI/CD: Integrated into GitLab, it provides CI/CD pipelines as part of GitLab's DevOps capabilities.

  • GitHub Actions: Provides CI/CD capabilities integrated directly into GitHub repositories.

Step 1- Choose GitHub Actions as CI Tool:

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows us to automate your build, test, and deployment pipeline. We can create workflows that build and test every pull request to our repository, or deploy merged pull requests to production.

image

Step 2- Understanding Branches:

In our project, we have multiple branches, including master, main, fiha, fiha-02, munira, munira2.0, tazim, tazim1.0, palash, sakib-01, and sakib-02. Each branch represents a different development environment or feature branch where we work on specific tasks.

Step 3- Setting Up CI Pipeline:

Terms commonly used in CI/CD Pipeline:

  • workflow: A workflow is a unit of automation from its start to finish, including the definition of what triggers the automation, what environment or other aspects should be taken into account during the automation, and what should happen as a result of the trigger.

  • Job: A job is a section of the workflow, and is made up of one or more steps. In this section of our workflow, the template defines the steps that make up the build job.

  • Step: A step represents one effect of the automation. A step could be defined as a GitHub Action, or another unit, like printing something to the console.

  • Action: An action is a piece of automation written in a way that is compatible with workflows. Actions can be written by GitHub, by the open source community, or we can write them ourself!

We will create a CI pipeline using GitHub Actions to automate the testing process whenever code changes are pushed to the repository. This pipeline will consist of the following stages:

Checkout Repository: This step ensures that the latest code changes are retrieved from the repository.

Install Dependencies: Install project dependencies using npm or yarn.

Run Tests: Execute unit tests using Jest to ensure code correctness.

Step 4- Configuring CI Workflow:

We will create a YAML configuration file (.github/workflows/main.yml) in the root directory of our project repository to define the CI workflow. This file will specify the steps to be executed in the CI pipeline. To create a YAML configuration file in our project repository, we will follow these steps:

  1. Navigate to the root directory of our project repository.
  2. Create a new file named .github/workflows/main.yml. We can do this using a text editor or through our command line interface.
  3. Open the main.yml file in preferred text editor.
  4. Write the YAML configuration for our CI workflow in this file. Below is an example of a basic CI workflow configuration:
name: Master.js CI

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [19.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
    
  
    - name: Install Backend Dependencies
      working-directory: backend
      run: npm install


    - name: Install Client Dependencies
      working-directory: client
      run: npm install

    - name: Run Backend Jest Tests
      working-directory: backend
      run: npm test     
  1. Save the changes to the main.yml file.
  2. Commit the main.yml file to your repository's master branch.
git add .github/workflows/main.yml  # Replace with the actual path if needed
git commit -m "Add CI workflow configuration"
git push origin <branch-name>  # Replace <branch-name> with the name of your branch

This configuration file specifies that the CI pipeline will be triggered on every push to any of the specified branches (master, main, fiha, etc.). It defines three steps: checking out the repository, installing dependencies, and running tests using Jest.

Step 5- Monitoring CI Results:

Once the CI pipeline is set up, we can monitor its execution by navigating to the "Actions" tab in our GitHub repository. We should review the test results and logs generated by GitHub Actions to identify any failures or issues.

image

Step 6- Integrating CI with Pull Requests:

To ensure that code changes are thoroughly tested before merging into the main branch, we can configure GitHub Actions to run tests automatically on pull requests. This allows us to review the test results and ensure that their changes do not introduce any regressions.

By implementing CI testing using GitHub Actions in our group project, we can ensure code quality, reliability, and consistency throughout the development process. CI testing helps identify and fix issues early, leading to faster release cycles and a more robust application.

Study on Continuous Integration Testing.pdf