lundi 30 décembre 2019

Validating the functionality of the application

I am trying to learn test script in python. I would like to write a test script to validate the functionality of an executable. The script should test the behaviour of the application, how the application handles error events and the specifications of the application are as follows,

  1. The application takes input data from a file that is specified as an argument and is called by executable.exe numbers.txt
  2. The numbers.txt file contains comma separated list of float number in each line
  3. The application computes and prints the average and standard deviation values for the numbers on each line in the input file(numbers.txt)

I came up till here

from validator_collection import validators, errors

# This funcion can be used to execute the application
# Inputs: executable, the executable file of the application
#         data, the input data file for the application
# Outputs: return code, standard output, and error output from the execution
def execute_application(executable, data):
    proc = subprocess.run(
            [executable, data],
            encoding="utf-8",
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
    return proc.returncode, proc.stdout, proc.stderr

# Call application
returncode, output, error = execute_application("executable.exe", "numbers.txt")

# The output of the program is 
#Output: data.txt
#Line 1 average 11.2333 standard deviation 9.34041
#Line 2 average 7.21667 standard deviation 7.29286

# started writing the test case
val = output.split(" ")
avg1, std1 = float(val[3]), float(val[6].strip('\nLine'))
avg2, std2 = float(val[9]), float(val[12].strip('\nLine'))
try:
    ret_avg1 = validators.float(avg1)
    ret_avg2 = validators.float(avg2)
    ret_std1 = validators.float(std1)
    ret_std2 = validators.float(std2)
except ValueError:
    print('Error')

print(ret_avg1, ret_avg2, ret_std1, ret_std2)
print("Output:", output)
print("Errors:", error)

Any pointers would be really helpful.

Aucun commentaire:

Enregistrer un commentaire