Making Test Results Pop with Slack: A Colorful Guide ๐ŸŒˆ

5 min read

Cover Image for 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 like 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, Team, 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 CICD 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. ๐ŸŽจ:

    1. If test result over 95%? Go with ๐ŸŸข green.

    2. If test result between 85% and 95%? Choose ๐ŸŸก yellow.

    3. 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 with Fun ๐ŸŽ€

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. Time to brighten up our chats! ๐Ÿš€๐ŸŽจ

Example of using Slack.

  • Use Slack Block Kit builder to craft your message, here are the templates for each.

  • Choose the approach, implement in your test automation framework or on CICD tools like Azure Devops, Jenkins and Github action.

  • Create secrets in you repo to store Webhook or Channel ID.

  • After execution calculate TOTAL_TESTS, PASSES, FAILURES, SUCCESS_RATE

  • Use these info in Slack Payload message.

Screenshots example ๐Ÿ–ผ๏ธ


Slack Implementation with Github Action

test-result.txt is test result generated by mvn command. And then use awk to extract value.

Content of test-result.txt in this example.

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

Example for yaml file.

      - 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 "| ๐ŸŒŸ Stellar 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  # Empty line to separate the tables
          echo "๐Ÿงญ Ready for the next adventure? Onward to the test results!" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY  # Empty line to separate the narrative from the table
          echo "๐Ÿ” **Automated Test Chronicles** ๐Ÿ”" >> $GITHUB_STEP_SUMMARY
          echo "Behold the saga of our automated tests in vivid detail!" >> $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