DEV Community


Posted on

Add Continuous Integration(CI) for my Java project

In order to ensure new changes won't break the test, I added Continuous Integration(CI) for my project ConvertTxtToHtml.

1. Add CI
Because my project is on GitHub, I choose to use GitHub Actions. I did it according to the GitHub document. I created a gradle.yml for my java project, and set steps for running the JUnit test.

name: Java CI with Gradle
    branches: [ "main" ]
    branches: [ "main" ]
  contents: read
    runs-on: ubuntu-latest
    - uses: actions/checkout@v3
    - name: Set up JDK 20
      uses: actions/setup-java@v3
        java-version: '20'
        distribution: 'temurin'
    - name: Run JUnit tests
      run: |
        export CLASSPATH=$CLASSPATH:$GITHUB_WORKSPACE/junit4.10/junit-4.10.jar
        cd $GITHUB_WORKSPACE/src
        java org.junit.runner.JUnitCore junit.ConvertTxtMdToHtmlTest
Enter fullscreen mode Exit fullscreen mode

2. Create a PR to test it
Then I wrote another unit test for my project and created a PR, then in the action, I could find my CI and built successfully!

Image description

3. Add test for other python project
In order to lean more about test and CI, I tried to add test for other project. til-page-builder is a command-line tool for authoring "Today I Learned" posts in Markdown, which can be converted to HTML for publishing on the web.

Image description

It is written in Python, the Author write detailed README and CONTRIBUTING, I can install, styling, linting, run test, get coverage successfully according to his document. Every step is clear and clean! It's really a good work.

Image description

This entire Python project structure is well-organized with well-defined functionality for each section. And the code is broken down into modules, each responsible for specific functionality, enhancing code maintainability and reusability.
I created a unit test for the src/utils/, I improved the coverage from 70%->84%

Image description

Image description

It was a valuable learning experience, especially in the world of continuous integration (CI) and testing. Through personal participation and practical application, I gained a deep understanding of the importance of CI pipelines and the important role of testing in software development.

Top comments (0)