onFailure
클래스: matlab.unittest.fixtures.Fixture
패키지: matlab.unittest.fixtures
픽스처 설정과 해제 중에 동적으로 실패에 대한 진단 추가
설명
onFailure(
는 픽스처 설정과 해제 루틴 동안 실패에 대한 진단을 추가합니다. 테스트 프레임워크에서 실패가 발견되면 진단이 실행됩니다. 기본적으로, 이러한 진단은 확인 실패, 어설션(assertion) 실패, 치명적 어설션(fatal assertion) 실패, uncaught exception이 발생할 때 실행됩니다. fixture
,failureDiag
)
onFailure(
은 테스트 프레임워크가 가정(assumption) 실패 시에도 진단을 실행하는지를 나타냅니다. 가정 실패 시에도 진단을 실행하려면 fixture
,failureDiag
,'IncludingAssumptionFailures',tf)tf
를 true
로 설정하십시오.
입력 인수
fixture
— 픽스처(Fixture)의 인스턴스
matlab.unittest.fixtures.Fixture
인스턴스
픽스처의 인스턴스로, matlab.unittest.fixtures.Fixture
로 지정됩니다.
failureDiag
— 진단 정보
문자형 벡터 | string형 배열 | 함수 핸들 | matlab.automation.diagnostics.Diagnostic
인스턴스의 배열
실패 시 표시할 진단 정보로, 문자형 벡터, string형 배열, 함수 핸들 또는 matlab.automation.diagnostics.Diagnostic
인스턴스의 배열로 지정됩니다.
예: @() disp('Failure Detected')
예: matlab.unittest.diagnostics.ScreenshotDiagnostic
tf
— 가정(assumption) 실패에 대한 반응
false
(디폴트 값) | true
가정(assumption) 실패에 대한 반응으로, false
(logical
0) 또는 true
(logical
1)로 지정됩니다. 기본적으로, 이 값은 false
이고 검증(verification) 실패, 어설션(assertion) 실패, 치명적 어설션(fatal assertion) 실패와 uncaught exception 발생 시 테스트 프레임워크가 진단을 실행합니다. 그러나, 가정(assumption) 실패 시에는 프레임워크가 진단을 실행하지 않습니다. 가정 실패 시 추가 진단을 실행하려면 이 값을 true
로 지정하십시오.
예제
픽스처 실패에 대한 진단 추가하기
현재 작업 폴더에 FormatHexFixture
픽스처를 만듭니다. 테스트 프레임워크는 픽스처 설정 도중 어설션 실패를 발견하고 실패 시 진단 메시지를 표시합니다.
classdef FormatHexFixture < matlab.unittest.fixtures.Fixture properties (Access=private) OriginalFormat end methods function setup(fixture) fixture.OriginalFormat = format().NumericFormat; format("hex") fixture.addTeardown(@format,fixture.OriginalFormat) fixture.onFailure(['Failure detected in ' mfilename("class")]) fixture.assertEqual(format().NumericFormat,"short") end end end
현재 작업 폴더에 다음 테스트 클래스인 SampleTest.m
을 생성합니다.
classdef SampleTest < matlab.unittest.TestCase methods (Test) function test1(testCase) testCase.applyFixture(FormatHexFixture); actStr = getColumnForDisplay([1;2;3], 'Small Integers'); expStr = ['Small Integers ' '3ff0000000000000' '4000000000000000' '4008000000000000']; testCase.verifyEqual(actStr, expStr) end end end function str = getColumnForDisplay(values, title) elements = cell(numel(values)+1, 1); elements{1} = title; for idx = 1:numel(values) elements{idx+1} = displayNumber(values(idx)); end str = char(elements); end function str = displayNumber(n) str = strtrim(evalc('disp(n);')); end
테스트를 실행합니다. "추가 진단" 제목 아래에 onFailure
진단이 나타납니다.
results = runtests('SampleTest');
Running SampleTest ================================================================================ Assertion failed in SampleTest/test1 and it did not run to completion. --------------------- Framework Diagnostic: --------------------- assertEqual failed. --> The strings are not equal. Actual Value: "hex" Expected Value: "short" ---------------------- Additional Diagnostic: ---------------------- Failure detected in FormatHexFixture ------------------ Stack Information: ------------------ In C:\work\FormatHexFixture.m (FormatHexFixture.setup) at 12 ================================================================================ . Done SampleTest __________ Failure Summary: Name Failed Incomplete Reason(s) ============================================================ SampleTest/test1 X X Failed by assertion.
버전 내역
R2017b에 개발됨R2019a: Access
특성이 protected
로 변경됨
onFailure
메서드의 Access
특성이 public
에서 protected
로 변경되었습니다. 이 변경 사항으로 인해 onFailure
사용은 matlab.unittest.fixtures.Fixture
클래스에서 파생된 클래스로 제한됩니다.
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)