필터 지우기
필터 지우기

Unit Testing: How to treat errors as failures

조회 수: 4 (최근 30일)
Christian Heigele
Christian Heigele 2017년 1월 24일
댓글: Andy Campbell 2017년 1월 24일
Whenever one of my functions throws an error that was not intended in that test-case the whole test suite stops. Is there any possibility to treat those error-occurrences as failures for those specific testcases and then continue with the next ones?
  댓글 수: 1
Andy Campbell
Andy Campbell 2017년 1월 24일
Hi Christian,
What test framework are you using? The framework that is officially included in MATLAB actually has the behavior you desire, unless something else is going on. Are you using the framework in the matlab.unittest package?
Andy

댓글을 달려면 로그인하십시오.

답변 (2개)

KSSV
KSSV 2017년 1월 24일
Read about try and catch
  댓글 수: 2
Christian Heigele
Christian Heigele 2017년 1월 24일
Since those functions are executed by the test runner, I could only surround the testRunner call with a try / catch statement, which doesn't help me to continue with the rest of test-cases within the loaded test suite.
Hence I don't think this is a valid solution.
% This suite consists out of a few hundred test-cases, of which a few might throw an error.
suite= TestSuite.fromFolder('../..', 'IncludingSubfolders', true);
runner = TestRunner.withNoPlugins();
results = runner.run(suite); % This call should continue executing all testcases within the suite, even if one of them has thrown an error.
display(results);
Christian Heigele
Christian Heigele 2017년 1월 24일
And of course I don't want to try/catch and omit the error inside of those functions, because the errors themselves are completely valid and helpful.

댓글을 달려면 로그인하십시오.


Adam
Adam 2017년 1월 24일
doc matlab.unittest.qualifications.Assumable
rather than using assert in a unit test will cause the test to be filtered rather than produce a failure. In this case the test suite should continue rather than terminate.
Be careful not to squash expected errors with this though.

카테고리

Help CenterFile Exchange에서 Run Unit Tests에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by