Example Test Script
Suppose let’s say the task is to validate whether a file is JSON or not in a list of files. We can write a test script to check the same.
Python3
# Python code to check whether # a file is JSON or not import os import sys import json if len (sys.argv) > 1 : if os.path.exists(sys.argv[ 1 ]): file = open (sys.argv[ 1 ], "r" ) json.load( file ) file .close() print ( "Validate JSON!" ) else : print (sys.argv[ 1 ] + " not found" ) else : print ( "Usage: testing_script.py <file>" ) |
Output 1- Pass Case
C:\QC_Work\Projects\Geeks\GPL\Python>python testing_script.py sample1.json
Validate JSON!Output 2- File to check is not entered
C:\QC_Work\Projects\Geeks\GPL\Python>python testing_script.py
Usage: testing_script.py <file>Output 3- Invalid File
C:\QC_Work\Projects\Geeks\GPL\Python>python testing_script.py sample3.json
sample3.json not found
What is a Test Script in Software Testing?
Active software projects are constantly changing – pages are being redesigned, user information is changing, and new functionality is being added. For it to work overtime, testers must make a constant effort to update the documents to match the new product. This can take a long time to test. Another challenge is that written tests are often designed to test the same thing over and over again, using the same steps and the same data each time testing. This means that if there are any bugs lying outside the guides provided in the test script, they will not be found unless the tester strays from the script. Written tests do not always encourage testers to use the intelligence and technical skills needed to detect hidden bugs. Here, we will discuss the following points:
- What is a Test Script?
- Why use Test Script?
- Approaches for writing a Test Script.
- Best Practices for writing a Test Script.
- Information in Test Script.
- Test Script vs Test Case.
- Example Test Script.
Let’s discuss each of these topics in detail.