Is the class-, function-, or script-based testing best for Unit Testing?
4 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2021-7-2
回答: MathWorks Support Team
2021-7-2
I want to unit-test my code but MATLAB has multiple approaches based on classes, scripts and functions. Which is the best?
采纳的回答
MathWorks Support Team
2021-7-2
Class-, function-, and script-based testing are all equally valid approaches. All three are also valid xUnit implementations. Which one is used is determined by the features one wants to use and what style he prefers and is comfortable with writing.
Class-based tests provide the most features (e.g., code sharing via inheritance, shared test fixtures, parameterized testing) while script-based tests offer fewer features. On the other hand, script-based tests are much easier to write, especially if one is not comfortable with object-oriented programming. Function-based tests are somewhere between class- and script-based tests on the ease-of-use vs. capability spectrum.
If you are interested in taking advantage of the most powerful features in the testing framework (and not averse to writing classes), it would be suggested to write class-based tests.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Write Unit Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!