Halmurat T.

Making Test Results Pop with Slack: A Colorful Guide

Making Test Results Pop with Slack: A Colorful Guide

The Spotlight on Test Scores

In the world of creating cool apps and websites, tests are like secret heroes that make sure everything works perfectly. But, what if nobody sees the signals from our heroes? That’s why showing test scores where everyone can see them is super important. You can use any chat app where your team hangs out, like Google Chat, Slack, or others, to share these scores.

Why Sharing in Chat Apps Rocks

Chat apps are like the main hangout for your team. When you share test scores there, it’s not just an update; it’s a way to start chats and get things moving. It’s turning “I didn’t see the test scores” into “Let’s fix this together!”

The Power of Colors and Emojis

Colors and emojis can speak faster than words:

  • Green for “Yay, everything’s great!”
  • Yellow for “Hmm, take a look!”
  • Red for “Oops, we need to fix this!”

Using emojis makes everything clearer and more fun!

How to Get Started

Here’s a simple guide to light up your team chat with test scores:

  1. Pick Your Chat App: Choose the app where your team hangs out and talks work. Slack, GoogleChat, Teams, Email.
  2. Craft Your Message: Think of putting together a fun message like building with blocks. You can share test scores and make them pop with emojis.
  3. Automate Your Tests: Use CI/CD tools to run your tests and schedule test for Smoke Test or Regression.
  4. Keep Secrets Safe: If you’re using Webhooks or special links, make sure to keep them secure, just like secret codes!
  5. Pick Your Color Code Based on test result:
    • If test result over 95%? Go with green.
    • If test result between 85% and 95%? Choose yellow.
    • If test result below 85%? It’s time for red.
  6. Share, React, Repeat: After setting it up, share your results, see how the team reacts, and keep improving.

Emojis and Colors Make It Better

Emojis and colors aren’t just fun; they’re like quick signals that help everyone understand test results at a glance:

  • Great job! (Score > 95%)
  • Almost there, need a little tweak. (Score 85-95%)
  • Attention needed, let’s fix it. (Score < 85%)

Wrapping Up

By using automation tools with your favorite chat app and a splash of colors and emojis, checking test scores becomes an engaging and fun part of your team’s day. It’s not just about making things automatic; it’s about ensuring everyone sees and reacts to every test score, making your project better together.

So, let’s make our test scores shine in our team chats, keeping our projects healthy and our team in sync.


Example: Slack Implementation with GitHub Actions

test-result.txt is a test result generated by mvn command. Then use awk to extract values.

Content of test-result.txt in this example:

Total tests run: 1150, Passes: 1150, Failures: 0, Skips: 0

Example YAML workflow:

- name: Slack Message
if: always()
id: result
run: |
CONTENT=$(cat target/test-result/test-result.txt)
echo $CONTENT
TOTAL_TESTS=$(echo $CONTENT | awk -F'[ ,]+' '{print $4}')
echo "totalText=$TOTAL_TESTS" >> "$GITHUB_OUTPUT"
PASSES=$(echo $CONTENT | awk -F'[ ,]+' '{print $6}')
echo "pass=$PASSES" >> "$GITHUB_OUTPUT"
FAILURES=$(echo $CONTENT | awk -F'[ ,]+' '{print $8}')
echo "fail=$FAILURES" >> "$GITHUB_OUTPUT"
SKIPS=$(echo $CONTENT | awk -F'[ ,]+' '{print $10}')
echo "skip=$SKIPS" >> "$GITHUB_OUTPUT"
if [ "$TOTAL_TESTS" -eq 0 ]; then
SUCCESS_RATE=0
else
SUCCESS_RATE=$(awk "BEGIN {printf \"%.2f\", ($PASSES/$TOTAL_TESTS)*100}")
fi
echo "rate=$SUCCESS_RATE" >> "$GITHUB_OUTPUT"
SLACK_MESSAGE_TEXT=""
INITIAL_COMMENT=""
if [ "$PLATFORM" == "Api" ]; then
SLACK_MESSAGE_TEXT="Api health check Here."
INITIAL_COMMENT="*_Download the API health check test report for Detailed View_*"
elif [ "$PLATFORM" == "Android" ]; then
SLACK_MESSAGE_TEXT="Android Test Result Here."
INITIAL_COMMENT="*_Download the Android test report for Detailed View_*"
else
SLACK_MESSAGE_TEXT="iOS Test Result Here."
INITIAL_COMMENT="*_Download the iOS test report for Detailed View_*"
fi
SLACK_MESSAGE_PAYLOAD=$(cat << EOF
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "$SLACK_MESSAGE_TEXT",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "The <${CURRENT_JOB_URL}|latest test run> has completed. Here are the details:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Test Suite:* $TEST_TYPE Test\n\n*Total Tests:* ${TOTAL_TESTS}\n\n*Tests Passed:* ${PASSES}\n\n*Tests Failed:* ${FAILURES}\n\n*Skips:* ${SKIPS}\n\n*Success Rate:* ${SUCCESS_RATE}%"
}
},
{
"type": "divider"
}
]
}
EOF
)
if [ $(echo "$SUCCESS_RATE < 100" | bc) -ne 0 ]; then
echo "Sending this payload to Slack: $SLACK_MESSAGE_PAYLOAD"
curl -X POST -H 'Content-type: application/json' --data "$SLACK_MESSAGE_PAYLOAD" $SLACK_WEBHOOK
else
echo "Hooray! The tests were completely successful with a 100% success rate. No issues detected."
echo "Success Rate: $SUCCESS_RATE%"
fi
- name: Summarized
run: |
echo "**Build and Release Odyssey**" >> $GITHUB_STEP_SUMMARY
echo "Dive into the details of our latest software expedition!" >> $GITHUB_STEP_SUMMARY
echo "| Details | Value |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
echo "| Release Number | $RELEASE_NUMBER |" >> $GITHUB_STEP_SUMMARY
echo "| Platform | $PLATFORM |" >> $GITHUB_STEP_SUMMARY
echo "| Test Type | $TEST_TYPE |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Automated Test Results**" >> $GITHUB_STEP_SUMMARY
echo "| Test Metrics | Value |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
echo "| Total Tests | ${{ steps.result.outputs.totalText }} |" >> $GITHUB_STEP_SUMMARY
echo "| Tests Passed | ${{ steps.result.outputs.pass }} |" >> $GITHUB_STEP_SUMMARY
echo "| Tests Failed | ${{ steps.result.outputs.fail }} |" >> $GITHUB_STEP_SUMMARY
echo "| Success Rate | ${{ steps.result.outputs.rate }}% |" >> $GITHUB_STEP_SUMMARY

Steps to implement

  • Use Slack Block Kit Builder to craft your message with color-coded attachments (green #3cb043, yellow #FFD700, red #ff0000).
  • Choose the approach: implement in your test automation framework or in CI/CD tools like Azure DevOps, Jenkins, or GitHub Actions.
  • Create secrets in your repo to store Webhook or Channel ID.
  • After execution, calculate TOTAL_TESTS, PASSES, FAILURES, SUCCESS_RATE.
  • Use these values in your Slack payload message.