How to test that a script is running correctly ?
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2022-12-16
编辑:Jan
2022-12-16
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Testing Frameworks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!