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!