A GUI to the new Unit Testing Framework

8 views (last 30 days)
Background
  • R2013a comes with a Unit Testing Framework with a text-based user interface
  • I picked up unit testing with the help of the FEX-contribution, munit, by Brad Phelan. It featured a GUI. mtest was broken by R2008a and it was never fixed.
  • I quickly "ported" munit to the new class system and has used my munit on a regular basis since then. There are issues, e.g. "cannot clear classes" forces me to restart munit and sometimes Matlab (R2012a).
Now it's time to switch to the new testing framework, but not without a GUI. I cannot find anything on a GUI for the testing framework here at Matlab Central.
.
Questions
  • Is there already a GUI for the testing framework underway?
  • The framework comes with Plugins, the documentation of which is terse. Is the user supposed to make Plugins?
  • How should a GUI for the framework be done?
  • Such a GUI would that be an appropriate task for a collaboration?

Accepted Answer

Andy Campbell
Andy Campbell on 25 Jul 2013
Edited: Andy Campbell on 30 Jul 2013
There is no separate GUI for the unit test framework other than the main MATLAB GUI, although you can easily run a single test using an editor feature. Let's say it is called "FooTest" and it is open in the MATLAB editor. If you click the little arrow on the green run button, then click in the area that says "type code to run", you can then add a "run" around the constructor call so the code to run changes from:
FooTest()
to:
run(FooTest())
Then, for FooTest you can always run it by simply clicking on the run button.
Another thing you might have success with is using shortcuts on the desktop in order to run common commands related to the test framework.
While there are a handful of plugins provided for the framework, creating your own custom plugin is not currently supported:
>> help matlab.unittest.plugins.TestRunnerPlugin
This class is undocumented and will change in a future release.
*EDIT*** Another option that I missed originally is simply using the public interface to create test suites from different test files, gathering them together and running them and analyzing and postprocessing the results. Note that this is something that a pretty nice GUI can be written around without needing to create your own custom plugin. For example, the following actions can definitely be wrapped up behind a MATLAB UI that you create
% Creating a suite from files, folders, packages, etc
import matlab.unittest.TestSuite;
fooSuite = TestSuite.fromClass(?FooTest);
singleMethodSuite = TestSuite.fromMethod(?SomeTest,'testSomethingMethod');
barSuite = TestSuite.fromFile('some/folder/BarTest.m')
feature1Suite = TestSuite.fromFolder('folder/with/tests/for/feature1');
feature2Suite = TestSuite.fromPackage('test.package.for.feature2');
% Combine the selected suites all together
fullSuiteToRun = [fooSuite, singleMethodSuite, barSuite, ...
feature1Suite, feature2Suite];
% Run the suite in "default" (non-silent) mode
results = run(fullSuiteToRun); % OR
results = fullSuiteToRun.run;
% Run the suite in silent mode
import matlab.unittest.TestRunner;
silentRunner = TestRunner.withNoPlugins;
results = runner.run(fullSuiteToRun);
% Analyze the results
% Get failing tests
failingTests = fullSuiteToRun([results.Failed])
% Get "incomplete" tests
incompleteTests = fullSuiteToRun([results.Incomplete])
% Get "long" tests (longer than, say, 10 seconds)
longTests = fullSuiteToRun([results.Duration > 10]);
So using this approach you can certainly create a GUI which helps you to select classes/files/methods as well as packages/folders. You can then use the selections from the gui to create the suites specified. Then you can certianly run these suites, choosing which (if any) of the available plugins you want installed to the TestRunner for this run. Then you can process the TestResult output to display information about the test run and its results.
Hope this helps! Andy

More Answers (0)

Categories

Find more on Testing Frameworks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!