Open In App

What is a Test Script in Software Testing?

Last Updated : 24 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  1. What is a Test Script?
  2. Why use Test Script?
  3. Approaches for writing a Test Script.
  4. Best Practices for writing a Test Script.
  5. Information in Test Script.
  6. Test Script vs Test Case.
  7. Example Test Script.

Let’s discuss each of these topics in detail.

What is a Test Script?

Test Scripts are line-by-line description that contains information about system functions that must be performed to verify an application or system under test. The test document should outline each step to be taken with the expected results. This automated script enables the tester to scan each level of a wide range of devices systematically. 

  • The test script should contain the entries to be included, as well as the expected results. 
  • The automated Scripts can be written using any programming language (C/C++/Python/Perl/ Batch Scripts).

Why use Test Script?

  1. Ensures nothing is skipped: Using the test script is the most reliable way to ensure that nothing is skipped during testing and that the results are accurate as the desired testing plan.
  2. User performance is important: Test scripts are important when the user requirements are specific.
  3. Tester browses product freely: Test scripts are useful in scenarios when the tester browses software freely and assumes that the function has an expected outcome when it does not. 
  4. Leaves less room for error: If the test script is well-prepared, it leaves less scope for error during the testing process. 

Approaches for Writing a Test Script

The following are some of the approaches used by the tester to write test scripts:

1. Record/ play: In this way, the tester needs to write any code instead of recording user actions. However, the tester will need to generate code to fix the faults or correct the default behavior. 

  • This method is easier than writing a complete test script from scratch because you already have the full code. 
  • It is widely used in simplified editing languages such as VBScript.

2. Keyword/ data-driven text: In this approach, there is a clear distinction between testers and developers. In the data-driven text, the tester describes the test using keywords without the knowledge of the source code. 

  • Here, the job of the developer is to apply the test script code for the keywords.
  • The tester does not have to worry about the system. 
  • However, they will rely heavily on development tools for any new functionality you want to check automatically.

3. Using Programming: If a tester likes to create a test script using this method, the tester will usually still be able to record or play again and produce a simple script. 

  • It is important to understand that one can choose the programming language even if the application is written in Java.
  • However, this does not mean that one needs to write the test scripts in Java, which can be difficult to read. 
  • Instead, one can write the test scripts in simple languages like Python or even can write a batch file.

Below is a sample Batch File to run web browsing:

set / a count = 0 : in am start – a android.intent.action.VIEW – d http: // m.google.com set / a count += 1 ECHO % COUNT% timeout / t 15 @goto in

Best Practices for Writing a Test Script

Here are some important tips for creating a test script:

  1. Clear, and Concise: The test script should be clear and should cover the scenario. If the tester always needs to ask the project manager to provide details about the application. This certainly wastes time and resources. To avoid this, one always needs to make sure that each step in the test script is clear, concise, and consistent to keep the testing process smooth.
  2. Well-Designed: Create a test script that must contain just one specific action that the testers will take. This ensures that each job is properly evaluated and that testers do not miss steps in the software testing process.
  3. Design from the user’s perspective: To design an effective test script, think from the user’s perspective and determine all the possible paths that the user will take to browse the product and decide which paths to test.
  4. Clearly written: The test script should be clearly written in easy-to-understand unambiguous language so that no features are missed in testing. 

Although different test engineers will have different preferences regarding the style, structure, and content of the text, compliance with the guidelines set by automated testing experts can be considered as a guide. 

Information in Test Script

A good script is always backed up with really useful information. The purpose of the script is what the text does or the actions we do. Potential information includes the following:

  1. Inputs and expected results: The raw content of the script i.e. inputs and sometimes expected results.
  2. User information: User information i.e. what information should be transferred to the script, what information should be restored, in what state the software being tested should be in when the script is called, and in what condition the software will remain at the end of the test.
  3. Usage information: Usage information i.e. additional information that is useful to testers, such as an explanation of why it is used in a particular way or references to similar tests that may need to be changed.
  4. Annotation: Annotation i.e. comments embedded in the entire script to indicate what happens in each logical step in terms of actions performed with the software being tested.

Test Script vs Test Case

Below are the differences between the test script and the test case:

Parameters

Test Case

Test Script

Definition Test cases contain a set of actions to be performed to verify a feature or performance. Test scripts are a set of Instructions to test software automatically.
Environment They are used in the manual testing environment. They are used in automation testing environments.
Derived from They are derived from Test Scenarios. They are derived from Test Cases.
Resources required More resources are needed. Less time to run the script, but more effort needs to be put in to study and implement.

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

Test Script

Fig 1.1 Test Script

Valid JSON File

Fig 1.2 Valid JSON File

Test Execution

Fig 1.3 Test Execution and Output



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads