Nella programmazione software, il modulo ETEST viene utilizzato per verificare la corretta funzionalità dei singoli metodi o algoritmi di un programma. ETEST è un metodo di test white-box, ossia il codice sorgente da verificare è noto quando si ideano casi di test e determinano i risultati attesi.
La procedura consiste generalmente in 3 passi:
inizializzazione dello stato iniziale
esecuzione dell'operazione da sottoporre a test
confronto dei risultati effettivi con i risultati previsti
Il driver di script ETEST esegue i task seguenti:
visualizzazione degli elementi di test
ricerca di test particolari
esecuzione di test particolari
Fare riferimento all'esempio seguente:
# Enable the new python 3 print syntax
from __future__ import print_function
# The path to the project
project_path = r"D:\PythonProjects\Example.project"
# Clean up any open project:
if projects.primary:
projects.primary.close()
# Load the project
proj = projects.open(project_path)
# Fetch the active application.
app = proj.active_application
# Create the online application for it.
onlineapp = online.create_online_application(app)
# Log in to the device.
onlineapp.login(OnlineChangeOption.Try, True)
# Start the application, if necessary.
if not onlineapp.application_state == ApplicationState.run:
onlineapp.start()
# Let the app do its work for some time...
system.delay(1000)
# This function runs the specified test/test series
def func_run_test(test_name):
print(test_name)
etest_test_provider.run_test(test_name)
while etest_test_provider.is_test_running:
system.delay(1000)
return
# Get all test series from the project
test_series = etest_test_provider.get_all_testseries()
# Run all test series
for test_object in test_series:
func_run_test(test_object)
# Get all test elements from test series "TS_MySeries"
test_elements = etest_test_provider.get_all_testelements("TS_MySeries")
if test_elements == None:
print ("No test series 'TS_MySeries' found")
else:
# Print all testelements
for test_element in test_elements:
print ("Found test element in Series TS_MySeries: " + test_element.Name)
# Run only "TS_Crank" test object
func_run_test(test_element.Name)
onlineapp.logout()
projects.primary.close()