In this Article, We are going to Learn How to test a Cron Job? Like a Pro 😎😎
Do you struggle with the Cron Job Testing,? Is your company demanding to Test some crons which are going to live in a few days?
These are exact strategies I have used to test multiple Cron jobs over 5 years of time.
So Let’s dive it…
- What is the Cron Job?
- How to test a Cron Job?
- Verify if It is scheduled correctly –
- Mock the Cron time
- Make it debuggable as QA
- As Devs to Switch On Logs
- Test Cron as CRUD
- Break the Flow of Cron and Verify
- Validate with Real Data
- Make sure About Server and System Time
- Verify Impact on the failure of Cron
- Break the Flow of Cron – Multiple times running it
- Risk of Failed Cron – Verify and Let Dev know
- Regression of Cron Job
- One Small Request:
- How to test a Cron Job?
What is the Cron Job?
The software utility Cron is a time-based job scheduler in Unix-like computer operating systems.
How to test a Cron Job?
Below are the few points/Pre-made Test cases for the Cron Job Testing:-
Verify if It is scheduled correctly –
- Open the Corntab – Its an online tool that will help you to Check the Cron time.
- You can enter the cron time and it will tell you when this cron will trigger.
- Note down the time and verify if its correct one.
Mock the Cron time
- To verify quickly Mock the Cron time by 1-2 minutes by changing it for quick testing (if it’s long for an hour/day long). – High
Make it debuggable as QA
- Ask the devs to create a shortcut for it. In the server or any other way to directly run it by you so that you can test it when you need.(saves time)
As Devs to Switch On Logs
- Ask dev to add the logs for monitor purpose and monitor it while testing.
Use below command for logs
* * * * * /path/script.sh &> /path/script.log or
tail -f /var/log/cron
Test Cron as CRUD
- Do testing by doing changing things as we do in CRUD(Not always, Crud means update/delete etc whichever is relevant) and verify results. – High
Break the Flow of Cron and Verify
- Break something the job relies on upon and schedule it to run again in a few minutes – Verify the results.
Validate with Real Data
- After deployment – Validate it with real data also. – High
Make sure About Server and System Time
- Keep system time and user system time in mind while testing CRON’s as scheduling is by server GMT time usually.
Verify Impact on the failure of Cron
- Negative scenario: What if CRON is stopped the midway execution, any impacts it will have?
Break the Flow of Cron – Multiple times running it
- Negative – Discuss with dev if there is any possibility of the same Cron getting run multiple times.
Risk of Failed Cron – Verify and Let Dev know
- Negative – Discuss with dev if it fails to the job – What is the risk/ solution for it(did we get the mail if it fails ?)
Regression of Cron Job
- Test for scenarios which shouldn’t get affected by Cron job(e.g. the other Cron should not affect other cron)
Let’s take an Example
This is sample Cron job template in crontab
0/1 * * * * /usr/bin/python /home/my_username/hello.py > /home/my_username/log.txt
# Hello world python program
print "Hello World!"
Check and Verify its scenarios.
Check out my other articles if you liked this.
15 Best Practices and Strategies for Test Automation
The Definitive Guide to Do API Testing in 2019
Ultimate Guide to Cross Browser Testing
One Small Request:
If you enjoyed reading this article, kindly give it a share. Your share is extremely helpful to spread our message and help more bloggers like you.
2 thoughts on “How to test Cron Job(Cron job testing)”