matlab.unittest.constraints.IssuesWarnings 클래스
네임스페이스: matlab.unittest.constraints
슈퍼클래스: matlab.unittest.constraints.Constraint
함수가 지정된 경고를 발생시키는지 테스트
설명
matlab.unittest.constraints.IssuesWarnings
클래스는 함수 핸들이 지정된 경고를 발생시키는지 테스트하는 제약 조건을 제공합니다.
matlab.unittest.constraints.IssuesWarnings
클래스는 handle
클래스입니다.
생성
설명
c = matlab.unittest.constraints.IssuesWarnings(
는 함수 핸들이 지정된 식별자를 사용하여 경고를 발생시키는지 테스트하는 제약 조건을 만듭니다. 이 제약 조건은 실제 값이 테스트 프레임워크 호출 시 지정된 경고를 발생시키는 함수 핸들인 경우에 충족됩니다. 기본적으로, 제약 조건은 경고가 발생하는 횟수, 경고의 발생 순서, 함수 핸들이 지정되지 않은 경고를 발생시키는지 여부를 무시합니다.identifiers
)
c = matlab.unittest.constraints.IssuesWarnings(
는 하나 이상의 이름-값 인수를 사용하여 옵션을 지정합니다. 예를 들어, identifiers
,Name,Value
)c = matlab.unittest.constraints.IssuesWarnings(identifiers,"WhenNargoutIs",2)
는 함수 핸들이 두 개의 출력 인수와 함께 호출될 때 지정된 경고를 발생시키는지 테스트하는 제약 조건을 만듭니다.
입력 인수
identifiers
— 경고 ID
string형 배열 | 문자형 벡터로 구성된 셀형 배열
경고 ID로, string형 배열 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다.
이 인수는 ExpectedWarnings
속성을 설정합니다.
예: "MATLAB:MKDIR:DirectoryExists"
예: ["MyComponent:FirstID" "MyComponent:SecondID"]
선택적 인수 쌍을 Name1=Value1,...,NameN=ValueN
으로 지정합니다. 여기서 Name
은 인수 이름이고 Value
는 대응값입니다. 이름-값 인수는 다른 인수 뒤에 와야 하지만, 인수 쌍의 순서는 상관없습니다.
예: c = matlab.unittest.constraints.IssuesWarnings(identifiers,WhenNargoutIs=2)
R2021a 이전 릴리스에서는 쉼표를 사용하여 각 이름과 값을 구분하고 Name
을 따옴표로 묶으십시오.
예: c = matlab.unittest.constraints.IssuesWarnings(identifiers,"WhenNargoutIs",2)
WhenNargoutIs
— 출력값 개수
0
(디폴트 값) | 음이 아닌 정수 스칼라
함수 핸들을 호출할 때 제약 조건이 요구하는 출력값 개수로, 음이 아닌 정수 스칼라로 지정됩니다.
이 인수는 Nargout
속성을 설정합니다.
데이터형: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
RespectingSet
— 예상 경고 집합을 고려하기 위한 옵션
false
또는 0
(디폴트 값) | true
또는 1
발생한 경고와 예상 경고를 비교할 때 예상 경고의 집합을 고려하기 위한 옵션으로, 숫자형 또는 논리값 0
(false
) 또는 1
(true
)로 지정됩니다. 이 값이 true
인 경우, 함수 핸들이 identifiers
에 나열되지 않은 경고를 발생시키면 제약 조건이 충족되지 않습니다. 기본적으로, 제약 조건은 함수 핸들이 발생시키는 예기치 않은 경고를 무시합니다.
이 인수는 RespectSet
속성을 설정합니다.
RespectingCount
— 개수를 고려하기 위한 옵션
false
또는 0
(디폴트 값) | true
또는 1
발생한 경고와 예상 경고를 비교할 때 개수를 고려하기 위한 옵션으로, 숫자형 또는 논리값 0
(false
) 또는 1
(true
)로 지정됩니다. 이 값이 true
인 경우, 함수 핸들이 예상 경고를 발생시키는 횟수가 identifiers
에 경고가 나열된 횟수와 다르면 제약 조건이 충족되지 않습니다. 기본적으로, 제약 조건은 경고가 발생하는 횟수를 무시합니다.
이 인수는 RespectCount
속성을 설정합니다.
RespectingOrder
— 순서를 고려하기 위한 옵션
false
또는 0
(디폴트 값) | true
또는 1
발생한 경고와 예상 경고를 비교할 때 순서를 고려하기 위한 옵션으로, 숫자형 또는 논리값 0
(false
) 또는 1
(true
)로 지정됩니다. 이 값이 true
인 경우, 함수 핸들이 경고를 발생시키는 순서가 identifiers
에 나열된 순서와 일치하지 않으면 제약 조건이 충족되지 않습니다. 기본적으로, 제약 조건은 경고가 발생하는 순서를 무시합니다.
제약 조건은 경고 프로파일을 연달아 반복되는 경고가 없는 프로파일로 잘라냄으로써 주어진 경고 프로파일의 순서를 결정합니다. 예를 들어, 순서 테스트 시 경고 프로파일 {id1,id1,id2,id3,id3,id3,id1,id1}
은 {id1,id2,id3,id1}
이 됩니다. 또한 제약 조건은 순서 테스트 시 발생한 경고 중 identifiers
에 나열되지 않은 경고를 모두 무시합니다.
이 인수는 RespectOrder
속성을 설정합니다.
Exactly
— 정확하게 일치하는지 테스트하기 위한 옵션
false
또는 0
(디폴트 값) | true
또는 1
발생한 경고와 예상 경고를 비교할 때 정확하게 일치하는지 테스트하기 위한 옵션으로, 숫자형 또는 논리값 0
(false
) 또는 1
(true
)로 지정됩니다. 이 값이 true
인 경우, 발생한 경고 프로파일과 예상 경고 프로파일이 정확히 동일하지 않으면 제약 조건이 충족되지 않습니다. 기본적으로 제약 조건은 정확한 비교를 수행하지 않습니다.
이 인수는 Exact
속성을 설정합니다.
속성
ExpectedWarnings
— 예상 경고 ID
문자형 벡터로 구성된 셀형 배열
예상 경고 ID로, 문자형 벡터로 구성된 셀형 배열로 반환됩니다. 제약 조건을 생성할 때 이 속성의 값을 지정합니다.
이 속성은 identifiers
입력 인수에 의해 설정됩니다.
특성:
GetAccess | public |
SetAccess | immutable |
FunctionOutputs
— 함수 핸들이 생성한 출력값
셀형 배열
테스트 프레임워크가 함수 핸들을 호출할 때 함수 핸들이 생성한 출력값으로, 셀형 배열로 반환됩니다.
특성:
GetAccess | public |
SetAccess | private |
Nargout
— 출력값 개수
0
(디폴트 값) | 음이 아닌 정수 스칼라
함수 핸들을 호출할 때 제약 조건이 요구하는 출력값 개수로, 음이 아닌 정수 스칼라로 반환됩니다.
이 속성은 WhenNargoutIs
이름-값 인수에 의해 설정됩니다.
특성:
GetAccess | public |
SetAccess | private |
RespectSet
— 예상 경고 집합을 고려하기 위한 옵션
0
(디폴트 값) | 1
발생한 경고와 예상 경고를 비교할 때 예상 경고의 집합을 고려하기 위한 옵션으로, logical
데이터형의 0
또는 1
로 반환됩니다. 기본적으로, 제약 조건은 함수 핸들이 발생시키는 예기치 않은 경고를 무시합니다.
이 속성은 RespectingSet
이름-값 인수에 의해 설정됩니다.
특성:
GetAccess | public |
SetAccess | private |
RespectCount
— 개수를 고려하기 위한 옵션
0
(디폴트 값) | 1
발생한 경고와 예상 경고를 비교할 때 개수를 고려하기 위한 옵션으로, logical
데이터형의 0
또는 1
로 반환됩니다. 기본적으로, 제약 조건은 경고가 발생하는 횟수를 무시합니다.
이 속성은 RespectingCount
이름-값 인수에 의해 설정됩니다.
특성:
GetAccess | public |
SetAccess | private |
RespectOrder
— 순서를 고려하기 위한 옵션
0
(디폴트 값) | 1
발생한 경고와 예상 경고를 비교할 때 순서를 고려하기 위한 옵션으로, logical
데이터형의 0
또는 1
로 반환됩니다. 기본적으로, 제약 조건은 경고가 발생하는 순서를 무시합니다.
이 속성은 RespectingOrder
이름-값 인수에 의해 설정됩니다.
특성:
GetAccess | public |
SetAccess | private |
Exact
— 정확하게 일치하는지 테스트하기 위한 옵션
0
(디폴트 값) | 1
발생한 경고와 예상 경고를 비교할 때 정확하게 일치하는지 테스트하기 위한 옵션으로, logical
데이터형의 0
또는 1
로 반환됩니다. 기본적으로 제약 조건은 정확한 비교를 수행하지 않습니다.
이 속성은 Exactly
이름-값 인수에 의해 설정됩니다.
특성:
GetAccess | public |
SetAccess | private |
예제
지정된 경고를 발생시키는지 테스트하기
실제 값이 지정된 경고를 발생시키는 함수 핸들인지 테스트합니다.
이 예제에서 사용되는 클래스를 가져옵니다.
import matlab.unittest.TestCase import matlab.unittest.constraints.IssuesWarnings
대화형 방식 테스트를 위한 테스트 케이스를 생성합니다.
testCase = TestCase.forInteractiveUse;
이 예제에서는 현재 폴더에 myFolder
라는 하위 폴더가 있다고 가정합니다. 하위 폴더가 존재하지 않으면 새로 만듭니다.
[~,~] = mkdir("myFolder")
mkdir
함수는 이미 존재하는 폴더를 만드는 데 사용되는 경우 경고를 발생시킵니다. 경고 ID를 반환합니다.
mkdir myFolder
[~,id] = lastwarn
Warning: Directory already exists. id = 'MATLAB:MKDIR:DirectoryExists'
기존 폴더를 만들기 위해 mkdir
을 호출하면 경고가 표시되는지, 그리고 경고에 식별자 "MATLAB:MKDIR:DirectoryExists"
가 있는지 확인합니다.
testCase.verifyThat(@() mkdir("myFolder"), ... IssuesWarnings("MATLAB:MKDIR:DirectoryExists"))
Verification passed.
경고를 발생시키지 않는 함수 핸들을 테스트합니다. 테스트가 실패합니다.
testCase.verifyThat(@dir,IssuesWarnings("MATLAB:MKDIR:DirectoryExists"))
. .. myFolder Verification failed. --------------------- Framework Diagnostic: --------------------- IssuesWarnings failed. --> The function handle did not issue a correct warning profile. The expected warning profile ignores: Set Count Order --> The function handle did not issue any warnings. Expected Warning Profile: --> 'MATLAB:MKDIR:DirectoryExists' Evaluated Function: function_handle with value: @dir
실제 값이 함수 핸들이 아닌 경우 제약 조건이 충족되지 않는지 확인합니다.
testCase.verifyThat(5,IssuesWarnings("MATLAB:MKDIR:DirectoryExists"))
Verification failed. --------------------- Framework Diagnostic: --------------------- IssuesWarnings failed. --> The value must be an instance of the expected type. Actual Class: double Expected Type: function_handle Actual Value: 5
여러 개의 경고를 발생시키는지 테스트하기
IssuesWarnings
제약 조건을 사용하여 여러 개의 경고를 발생시킬 수 있는 함수 핸들을 테스트합니다.
현재 폴더의 파일에서 myfun
함수를 만듭니다. 이 함수는 경고 ID로 구성된 배열을 입력값으로 받고 지정된 식별자에 해당하는 경고를 발생시킵니다.
function myfun(id) arguments id {mustBeText,mustBeNonempty} end for i = 1:numel(id) warning(string(id(i)),"Warning!") end end
이 예제에서 사용되는 클래스를 가져옵니다.
import matlab.unittest.TestCase import matlab.unittest.constraints.IssuesWarnings
IssuesWarnings
제약 조건을 시험하기 위해 여러 경고 ID와 대화형 방식 테스트를 위한 테스트 케이스를 만듭니다.
id1 = "MyComponent:FirstID"; id2 = "MyComponent:SecondID"; id3 = "MyComponent:ThirdID"; testCase = TestCase.forInteractiveUse;
특정 ID를 사용하여 호출할 때 myfun
이 경고를 발생시키는지 확인합니다.
testCase.verifyThat(@() myfun(id1),IssuesWarnings(id1))
Verification passed.
myfun
이 예기치 않은 경고를 발생시키는 경우 제약 조건이 충족되지 않는지 확인합니다.
testCase.verifyThat(@() myfun(id1),IssuesWarnings(id2))
Warning: Warning! ... Verification failed. --------------------- Framework Diagnostic: --------------------- IssuesWarnings failed. --> The function handle did not issue a correct warning profile. The expected warning profile ignores: Set Count Order --> The function handle did not issue the correct warning(s). Missing Warning(s): --> 'MyComponent:SecondID' Actual Warning Profile: --> 'MyComponent:FirstID' Expected Warning Profile: --> 'MyComponent:SecondID' Evaluated Function: function_handle with value: @()myfun(id1)
함수 핸들이 여러 경고를 발생시킬 때의 함수 핸들을 테스트합니다. myfun
이 두 개의 예상 경고를 모두 발생시키기 때문에 이 테스트가 성공합니다.
testCase.verifyThat(@() myfun([id1 id3 id2 id1]), ...
IssuesWarnings([id2 id1]))
Verification passed.
다시 테스트하되, 이번에는 예상 경고 집합을 고려합니다. myfun
이 예상 경고 외에 id3
경고를 발생시키므로 테스트가 실패합니다.
testCase.verifyThat(@() myfun([id1 id3 id2 id1]), ... IssuesWarnings([id2 id1],"RespectingSet",true))
Warning: Warning! ... Verification failed. --------------------- Framework Diagnostic: --------------------- IssuesWarnings failed. --> The function handle did not issue a correct warning profile. The expected warning profile respects: Set The expected warning profile ignores: Count Order --> The function handle did not issue the correct warning(s). Extra Warning(s): --> 'MyComponent:ThirdID' Actual Warning Profile: --> 'MyComponent:FirstID' --> 'MyComponent:ThirdID' --> 'MyComponent:SecondID' --> 'MyComponent:FirstID' Expected Warning Profile: --> 'MyComponent:SecondID' --> 'MyComponent:FirstID' Evaluated Function: function_handle with value: @()myfun([id1,id3,id2,id1])
경고 개수를 고려하여 myfun
이 지정된 경고를 발생시키는지 테스트합니다. 함수 핸들이 예상 경고 프로파일에서와 동일한 횟수만큼 각각의 예상 경고를 발생시키므로 테스트가 성공합니다.
testCase.verifyThat(@() myfun([id2 id1 id3 id2]), ... IssuesWarnings([id1 id2 id2],"RespectingCount",true))
Verification passed.
경고 순서를 고려하여 myfun
이 지정된 경고를 발생시키는지 확인합니다.
testCase.verifyThat(@() myfun([id1 id2 id2 id3]), ... IssuesWarnings([id1 id2],"RespectingOrder",true))
Verification passed.
경고 집합, 개수 및 순서를 고려하여 myfun
이 지정된 경고를 발생시키는지 테스트합니다. 테스트가 통과합니다.
testCase.verifyThat(@() myfun([id1 id1 id2 id1]), ... IssuesWarnings([id1 id2 id1 id1], ... "RespectingSet",true,"RespectingCount",true,"RespectingOrder",true))
Verification passed.
이전 테스트에서는 경고 집합, 개수 및 순서를 고려하는 경우 함수 핸들이 제약 조건을 충족하지만 발생한 경고 프로파일과 예상 경고 프로파일이 정확히 동일하지는 않았습니다. 정확히 일치하는지 테스트할 경우 제약 조건은 충족되지 않습니다.
testCase.verifyThat(@() myfun([id1 id1 id2 id1]), ... IssuesWarnings([id1 id2 id1 id1],"Exactly",true))
Warning: Warning! ... Verification failed. --------------------- Framework Diagnostic: --------------------- IssuesWarnings failed. --> The function handle did not issue a correct warning profile. The expected warning profile must match exactly. --> The function handle did not issue the exact warning profile expected. Actual Warning Profile: --> 'MyComponent:FirstID' --> 'MyComponent:FirstID' --> 'MyComponent:SecondID' --> 'MyComponent:FirstID' Expected Warning Profile: --> 'MyComponent:FirstID' --> 'MyComponent:SecondID' --> 'MyComponent:FirstID' --> 'MyComponent:FirstID' Evaluated Function: function_handle with value: @()myfun([id1,id1,id2,id1])
버전 내역
R2013a에 개발됨
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)