Skip to content

Commit

Permalink
Merge pull request MOxUnit#6 from scottclowe/time-functions
Browse files Browse the repository at this point in the history
NF: add timing of unit tests
  • Loading branch information
nno committed Dec 6, 2015
2 parents d2995f6 + fe4f0cd commit f973e64
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
9 changes: 5 additions & 4 deletions MOxUnit/@MOxUnitFunctionHandleTestCase/run.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
%
% NNO 2015

start_tic = tic;
try
passed=false;
try
Expand All @@ -32,16 +33,16 @@
end

reason=e.message((last_newline_pos+1):end);
result=addSkip(result, obj, reason);
result=addSkip(result, obj, toc(start_tic), reason);
else
result=addFailure(result, obj, e);
result=addFailure(result, obj, toc(start_tic), e);
end
end

if passed
result=addSuccess(result, obj);
result=addSuccess(result, obj, toc(start_tic));
end
catch
e=lasterror();
result=addError(result, obj, e);
result=addError(result, obj, toc(start_tic), e);
end
1 change: 1 addition & 0 deletions MOxUnit/@MOxUnitTestResult/MOxUnitTestResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
s.skips=cell(0);
s.successes=cell(0);
s.testsRun=0;
s.duration=0;
obj=class(s,'MOxUnitTestResult');

6 changes: 4 additions & 2 deletions MOxUnit/@MOxUnitTestResult/addError.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
function obj=addError(obj,t,e)
function obj=addError(obj,t,dur,e)
% Add test case error to a MoxUnitTestResult instance
%
% obj=addError(obj,t,e)
%
% Inputs:
% obj MOxUnitTestResult instance.
% t MoxUnitTestCase that gave an error.
% dur Duration of runtime until error (in seconds).
% e Exception associated with the error.
%
% Output:
Expand All @@ -14,6 +15,7 @@
% NNO 2015


obj.failures{end+1}={t,e};
obj.failures{end+1}={t,dur,e};
obj.testsRun=obj.testsRun+1;
obj.duration=obj.duration+dur;
report(obj,'e','Error',t);
6 changes: 4 additions & 2 deletions MOxUnit/@MOxUnitTestResult/addFailure.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
function obj=addFailure(obj,t,e)
function obj=addFailure(obj,t,dur,e)
% Add test case failure to a MoxUnitTestResult instance
%
% obj=addError(obj,t,e)
%
% Inputs:
% obj MOxUnitTestResult instance.
% t MoxUnitTestCase that gave a failure.
% dur Duration of runtime until failure (in seconds).
% e Exception associated with the failure.
%
% Output:
% obj MOxUnitTestResult instance with the failure added.
%
% NNO 2015

obj.failures{end+1}={t,e};
obj.failures{end+1}={t,dur,e};
obj.testsRun=obj.testsRun+1;
obj.duration=obj.duration+dur;
report(obj,'F','FAILED',t);
7 changes: 5 additions & 2 deletions MOxUnit/@MOxUnitTestResult/addSkip.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
function obj=addSkip(obj,t,reason)
function obj=addSkip(obj,t,dur,reason)
% Add test case skip to a MoxUnitTestResult instance
%
% obj=addError(obj,t,e)
%
% Inputs:
% obj MOxUnitTestResult instance.
% t MoxUnitTestCase that gave an error.
% dur Duration of runtime until skipped (in seconds).
% reason String describing the reason why a test was skipped.
%
% Output:
Expand All @@ -14,7 +15,9 @@
%
% NNO 2015

obj.skips{end+1}={t,reason};
obj.skips{end+1}={t,dur,reason};
obj.testsRun=obj.testsRun+1;
obj.duration=obj.duration+dur;
report(obj,'s','SKIP',t);


6 changes: 4 additions & 2 deletions MOxUnit/@MOxUnitTestResult/addSuccess.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
function obj=addSuccess(obj,t)
function obj=addSuccess(obj,t,dur)
% Add test case success (pass) to a MoxUnitTestResult instance
%
% obj=addError(obj,t,e)
%
% Inputs:
% obj MOxUnitTestResult instance.
% t MoxUnitTestCase that gave a success.
% dur Duration of runtime (in seconds).
%
% Output:
% obj MOxUnitTestResult instance with the test success added.
%
% NNO 2015

obj.successes{end+1}=t;
obj.successes{end+1}={t,dur};
obj.testsRun=obj.testsRun+1;
obj.duration=obj.duration+dur;
report(obj,'.','passed',t);

2 changes: 1 addition & 1 deletion MOxUnit/@MOxUnitTestResult/show_non_successes.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function show_non_successes(obj, label)
label_singular=label(1:(end-1));

for k=1:n
e=content{k}{2};
e=content{k}{3};
if isstruct(e)
fprintf(stream,'%s: %s\n',label_singular,e.message);
for j=1:numel(e.stack)
Expand Down

0 comments on commit f973e64

Please sign in to comment.