DEV Community

WangGithub0
WangGithub0

Posted on

3

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
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
permissions:
  contents: read
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 20
      uses: actions/setup-java@v3
      with:
        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/commandline.py, 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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay