5 isConsoleOutputCollected
11 self.emailLogger=emailLogger;
12 self.fTempDirGetter=fTempDirGetter;
13 [~,~,
self.isConsoleOutputCollected]=
parseparext(varargin,...
14 {
'isConsoleOutputCollected';...
16 'islogical(x)&&isscalar(x)'},0);
19 function resultVec=runTestPack(
self,topPackageName,varargin)
23 [testPackArgList,~,isJUnitXMLReportEnabled,jUnitXMLReportDir,...
24 isJUnitReportEnabledSpec,isJUnitXMLReportDirSpec]=...
26 {
'isJUnitXMLReportEnabled',
'jUnitXMLReportDir';...
28 'islogical(x)',
'isstring(x)'});
29 if isJUnitReportEnabledSpec&&~isJUnitXMLReportDirSpec
30 throwerror(
'wrongInput',[
'jUnitXMLReportDir property',...
31 'is obligatory when isJUnitXMLReportEnabled=true']);
34 self.emailLogger.sendMessage(
'STARTED',
'');
35 tmpDirName=
self.fTempDirGetter(topPackageName);
37 logger=Log4jConfigurator.getLogger();
38 isConsoleOutputCollected=
self.isConsoleOutputCollected; %#ok<*PROPLC>
40 suite=testsuite(topPackageName,
'IncludeSubpackages',
true);
41 runner=matlab.unittest.TestRunner.withNoPlugins;
43 if isJUnitXMLReportEnabled
48 xmlFile = [jUnitXMLReportDir,
filesep,
'test_results.xml'];
49 p=matlab.unittest.plugins.XMLPlugin.producingJUnitFormat(xmlFile);
53 fRun=@()runner.run(suite);
55 if isConsoleOutputCollected
56 consoleOutStr=evalc(...
57 'resultVec=feval(fRun,testPackArgList{:});');
59 resultVec=feval(fRun,testPackArgList{:});
62 errorFailStr=getErrorFailMessage(resultVec);
63 errorHyperStr=errorFailStr;
64 isFailed=~getIsPassed(resultVec);
66 subjectStr=getMinimalReport(resultVec);
68 if isConsoleOutputCollected
69 consoleOutFileName=writeMessageToFile(
'console_output',...
71 consoleOutZipFileName=[tmpDirName,
filesep,
'cosoleOutput.zip'];
72 zip(consoleOutZipFileName,consoleOutFileName);
73 attachFileNameList={consoleOutZipFileName};
75 attachFileNameList={};
84 attachFileNameList={};
88 errorFailFileName=writeMessageToFile(
'error_fail_list',...
90 attachFileNameList=[attachFileNameList,{errorFailFileName}];
91 logger.error(errorHyperStr);
94 self.emailLogger.sendMessage(subjectStr,...
95 'emailAttachmentNameList',attachFileNameList);
97 function fullFileName=getFullFileName(shortFileName,extName)
101 fullFileName=[tmpDirName,
filesep,shortFileName,extName];
103 function fullFileName=writeMessageToFile(shortFileName,msgStr)
104 fullFileName=getFullFileName(shortFileName);
105 [fid,errMsg] = fopen(fullFileName,
'w');
110 fprintf(fid,
'%s',msgStr);
121 function resultVec=runTestsWithConf(inpArgList,confRepoMgr,log4jConfiguratorName,emailSubjSuffixName,runnerName,fTempDirGetter,topPackageName,varargin)
125 import(log4jConfiguratorName);
129 confName=confRepoMgr.getCurConfName(); %#ok<NASGU>
130 Log4jConfigurator.unlockConfiguration();
131 Log4jConfigurator.configure(confRepoMgr);
132 Log4jConfigurator.lockConfiguration();
134 logger=Log4jConfigurator.getLogger();
135 logger.info(sprintf(
'Test configuration:\n%s',...
136 evalc(
'strucdisp(confRepoMgr.getConf(confName))')));
140 confRepoMgr,runnerName,emailSubjSuffixName,....
141 Log4jConfigurator.getMainLogFileName(),fTempDirGetter);
144 testRunner=MUnitRemoteTestRunner(emailLogger,...
145 fTempDirGetter,varargin{:});
147 isJUnitXMLReportEnabled=confRepoMgr.getParam(...
148 'reporting.JUnitXMLReport.isEnabled');
149 dirNameByTheFollowingFile=confRepoMgr.getParam(...
150 'reporting.JUnitXMLReport.dirNameByTheFollowingFile');
151 dirNameSuffix=confRepoMgr.getParam(...
152 'reporting.JUnitXMLReport.dirNameSuffix');
153 jUnitXMLReportRootDir=fileparts(which(dirNameByTheFollowingFile));
155 if isempty(jUnitXMLReportRootDir)
156 throwerror(
'notExistentRefFile',[
'file %s by which the ',...
157 'directory for JUnit XML reports is build doesn''t exist'],...
158 dirNameByTheFollowingFile);
161 jUnitXMLReportDir=[fileparts(which(...
162 dirNameByTheFollowingFile)),
filesep,...
165 inpArgList=[inpArgList,{
'isJUnitXMLReportEnabled',...
166 isJUnitXMLReportEnabled,...
167 'jUnitXMLReportDir',jUnitXMLReportDir}];
169 resultVec=testRunner.runTestPack(topPackageName,...
172 emailLogger.sendMessage(
'ERROR',...
183 function reportStr=getErrorFailMessage(testResVec)
184 isEmptyVec=arrayfun(@(x)~isfield(x.Details,
'DiagnosticRecord')||...
185 isfield(x.Details,
'DiagnosticRecord')&&...
186 isempty(x.Details.DiagnosticRecord),testResVec);
187 reportStrList=arrayfun(@(x)x.Details.DiagnosticRecord.Report,...
188 testResVec(~isEmptyVec),
'UniformOutput',
false);
189 reportStr=sprintf(
'%s\n',reportStrList{:});
191 function isPassed=getIsPassed(testResVec)
192 isPassed=(sum([testResVec.Failed])+sum([testResVec.Incomplete]))==0;
194 function reportStr=getMinimalReport(testResVec)
195 nTests=numel(testResVec);
196 runTime=sum([testResVec.Duration]);
197 nFails=sum([testResVec.Failed]);
198 nIncomplete=sum([testResVec.Incomplete]);
200 msgFormatStr=
'<< %s >> || TESTS: %d';
201 suffixStr=
', RUN TIME(sec.): %.5g';
203 if (nFails==0)&&(nIncomplete)==0
208 msgFormatStr=[msgFormatStr,...
209 ', FAILURES: %d, INCOMPLETE: %d'];
210 addArgList={nFails,nIncomplete};
212 msgFormatStr=[msgFormatStr,suffixStr];
213 reportStr=sprintf(msgFormatStr,prefixStr,...
214 nTests,addArgList{:},runTime);
LOG4JCONFIGURATOR simplifies log4j configuration, especially when Parallel Computing Toolbox is used...
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function parseparext(in args, in propNameValMat, in varargin)
PARSEPAREXT behaves in the same way as mxberry.core.parseparams but returns property values in a more...
static function fromConfRepoMgr(in confRepoMgr, in appName, in inpSubjSuffName, in mainLogFileName, in fTempDirGetter, in varargin)