이 페이지의 최신 내용은 아직 번역되지 않았습니다. 최신 내용은 영문으로 볼 수 있습니다.
이 예제에서는 테스트 실행기에 플러그인을 추가하는 방법을 보여줍니다. matlab.unittest.plugins.TestRunProgressPlugin
은 테스트 케이스에 대한 진행 상황 메시지를 표시합니다. 이 플러그인은 matlab.unittest
패키지의 일부입니다. MATLAB®은 디폴트 테스트 실행기에 이 플러그인을 사용합니다.
작업 폴더의 파일에서 BankAccount
클래스에 대한 테스트 파일을 만드십시오.
type BankAccountTest.m
classdef BankAccountTest < matlab.unittest.TestCase % Tests the BankAccount class. methods (TestClassSetup) function addBankAccountClassToPath(testCase) p = path; testCase.addTeardown(@path,p); addpath(fullfile(matlabroot,'help','techdoc','matlab_oop',... 'examples')); end end methods (Test) function testConstructor(testCase) b = BankAccount(1234, 100); testCase.verifyEqual(b.AccountNumber, 1234, ... 'Constructor failed to correctly set account number'); testCase.verifyEqual(b.AccountBalance, 100, ... 'Constructor failed to correctly set account balance'); end function testConstructorNotEnoughInputs(testCase) import matlab.unittest.constraints.Throws; testCase.verifyThat(@()BankAccount, ... Throws('MATLAB:minrhs')); end function testDesposit(testCase) b = BankAccount(1234, 100); b.deposit(25); testCase.verifyEqual(b.AccountBalance, 125); end function testWithdraw(testCase) b = BankAccount(1234, 100); b.withdraw(25); testCase.verifyEqual(b.AccountBalance, 75); end function testNotifyInsufficientFunds(testCase) callbackExecuted = false; function testCallback(~,~) callbackExecuted = true; end b = BankAccount(1234, 100); b.addlistener('InsufficientFunds', @testCallback); b.withdraw(50); testCase.assertFalse(callbackExecuted, ... 'The callback should not have executed yet'); b.withdraw(60); testCase.verifyTrue(callbackExecuted, ... 'The listener callback should have fired'); end end end
명령 프롬프트에서, BankAccountTest
테스트 케이스로부터 테스트 스위트 ts
를 만드십시오.
ts = matlab.unittest.TestSuite.fromClass(?BankAccountTest);
플러그인이 없는 테스트 실행기를 만드십시오.
runner = matlab.unittest.TestRunner.withNoPlugins; res = runner.run(ts);
출력값이 표시되지 않습니다.
사용자 지정 플러그인 TestRunProgressPlugin
을 추가합니다.
import matlab.unittest.plugins.TestRunProgressPlugin
runner.addPlugin(TestRunProgressPlugin.withVerbosity(2))
res = runner.run(ts);
Running BankAccountTest ..... Done BankAccountTest __________
MATLAB은 BankAccountTest
에 대한 진행 상황 메시지를 표시합니다.