How to test that a script is running correctly ?
7 views (last 30 days)
Show older comments
Hello
I'm trying to implement an acceptance test for the matlab code I'm working on with other people. For this I would like to test some script to be sure that even after some change they're still working.
I saw that there's the functiun runtests but it only test that functiuns give the good output, it doesnt check for script.
I tried this but then all of the script are in the same workspace and they might interact with each other when we don't want. Also some script have "clc" or "clear all" in them wich also causes some issue.
try
fprintf("testing %s\n",filename)
[~] = evalc(filename);
fprintf("%s run properly\n",filename)
catch
fprintf("%s didn't run properly\n",filename)
end
The ideal situtation would be to be able to run the script in another session and just get the information that the script completed without displaying any of the output
0 Comments
Accepted Answer
Jan
on 16 Dec 2022
Edited: Jan
on 16 Dec 2022
The is no way to prove the correct working of scripts. The danger of interferences between scripts, e.g. by clear all commands, is high and the number of possible problems is infinite. Therefore productive work use functions only and avoid scripts strictly.
Functions encapsulate the internal implementation, such that interferences with the outside can happen over the defined input and output arguments only. Therefore well defined unit-testing is possible, which compares the behavior of a function for valid and invalid input.
Automatic testing of scripts is not possible, because the scripts can and will destroy the test environment of the calling function. Especially if you collaborate with a team, scripts are a shot inyour knee.
0 Comments
More Answers (0)
See Also
Categories
Find more on Testing Frameworks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!