Logo

dev-resources.site

for different kinds of informations.

Junit Badge For Git Project

Published at
5/4/2024
Categories
github
junit
java
maven
Author
vishalmysore
Categories
4 categories in total
github
open
junit
open
java
open
maven
open
Author
12 person written this
vishalmysore
open
Junit Badge For Git Project

What are badges?

They look like this Image description

Now lets create a custom badge for your git project

The Plugins to update the JUnit test number seem not working very well specially if you do not have JaCOCO , here is a simple work around

1) Create a GIST file

https://docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists

2)Get your GIST ID
https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28

3)Create GIT TOken with GIST permission
https://docs.github.com/en/[email protected]/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

4)Add The token to your repo secret for action

5)Create shell script



#!/bin/bash

# Assuming Maven generates XML test reports in the "target/surefire-reports" directory
TEST_REPORT_DIR="target/surefire-reports"
# Print current directory
echo "Current directory: $(pwd)"

xml_files=$(find "$(pwd)" -name "TEST-*.xml")

# Concatenate all XML files and count the occurrences of "<testcase" using grep
test_count=$(cat $xml_files | grep -c "<testcase")
echo "Total number of tests: $test_count"




echo "GIST_ID: $GIST_ID"


json_data='{"schemaVersion": "1", "label": "testcount", "message": "'$test_count'", "color": "orange"}'

echo "JSON data: $json_data"

# Prevent any output from the script
exec > /dev/null
exec 2>&1

# Create or update the Gist with the test count
curl -s -X PATCH \
     -H "Authorization: token $GIST_TOKEN" \
     -H "Content-Type: application/vnd.github+json" \
     -d '{"files":{"test.json":{"content": "{\"schemaVersion\": 1,\"label\": \"testcount\", \"message\": \"'$test_count'\", \"color\":\"orange\"}" }}}' \
     "https://api.github.com/gists/$GIST_ID"


Enter fullscreen mode Exit fullscreen mode

7)Add script to your workflow



      - name: Upload test custom
        env:
          GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
          GIST_ID: ${{ secrets.GIST_ID }}
        run: bash uploadnumber.sh


Enter fullscreen mode Exit fullscreen mode

8)Create the Shield badge from the raw gist file
https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/{gitusername}/{gist_id}/raw/{file_name}

maven Article's
30 articles in total
Favicon
SpringBoot Web Service - Part 5 - Github Action
Favicon
SpringBoot Web Service - Part 2 - Preparing Using Spring Initializr
Favicon
SpringBoot Web Service - Part 1 - Create Repository
Favicon
SpringBoot Web Service - Part 4 - Initial Configuration
Favicon
Identifying and Removing Unused Dependencies in pom.xml
Favicon
JeKa: The Simplest Way to Start with Java for Real
Favicon
JeKa: The Simplest Way to Create Uber and Shade Jars
Favicon
JeKa: The Simplest Way to Publish on Maven Central
Favicon
Preparando o ambiente de desenvolvimento da melhor API de tabelas de campeonato que vocรช jรก viu!
Favicon
Maven Guide for Beginners
Favicon
Wednesday Links - Edition 2024-10-16
Favicon
Unlock 10% Discounts in 5 Minutes: Build a Drools Project with Maven
Favicon
Getting Started with Maven
Favicon
Quick fix: com.github.everit-org.json-schema:org.everit.json.schema:jar:1.12.2 was not found
Favicon
How to deploy to maven central repo
Favicon
No SNAPSHOTs
Favicon
Maven Commands Cheat Sheet
Favicon
Apache Maven Kirish
Favicon
Difference between mvn install and mvn package
Favicon
Adding Liquibase plugin into Apache Maven managed project
Favicon
Accelerate Maven Application Builds: Maximizing Efficiency with Docker Volumes for Maven Repository Sharing
Favicon
Check for newer versions of dependencies in pom.xml
Favicon
Accelerate Your Automation Testing with Maven: A Step-by-Step Guide ๐Ÿš€
Favicon
Junit Badge For Git Project
Favicon
Jenkins CICD
Favicon
Set JVM Timezone when running JUnit 5 tests
Favicon
Maven 4 - Part I - Easier Versions
Favicon
An Updated Guide to Maven Archetypes
Favicon
H2 database Setup Error Unable to load name org.hibernate.dialect.Oracle10gDialect
Favicon
Why I prefer Maven over Gradle

Featured ones: