diff --git a/.gitignore b/.gitignore index e694a40..7a70029 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .buildtool/ releases/ -tbx/testframeworkextensionsdoc/*.html -tbx/testframeworkextensionsdoc/*.xml -tbx/testframeworkextensionsdoc/resources -tbx/testframeworkextensionsdoc/helpsearch-v4_en/ \ No newline at end of file +tbx/testextdoc/*.html +tbx/testextdoc/*.xml +tbx/testextdoc/resources +tbx/testextdoc/helpsearch-v4_en/ \ No newline at end of file diff --git a/resources/project/Root.type.Files/tbx.type.File/testext.type.File/Testable.m.type.File.xml b/resources/project/Root.type.Files/tbx.type.File/testext.type.File/Testable.m.type.File.xml new file mode 100644 index 0000000..378b613 --- /dev/null +++ b/resources/project/Root.type.Files/tbx.type.File/testext.type.File/Testable.m.type.File.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/tbx.type.File/testextdoc.type.File/Testable.md.type.File.xml b/resources/project/Root.type.Files/tbx.type.File/testextdoc.type.File/Testable.md.type.File.xml new file mode 100644 index 0000000..7825d83 --- /dev/null +++ b/resources/project/Root.type.Files/tbx.type.File/testextdoc.type.File/Testable.md.type.File.xml @@ -0,0 +1,2 @@ + + diff --git a/tbx/testext/Contents.m b/tbx/testext/Contents.m index 34fe51e..86fa31a 100644 --- a/tbx/testext/Contents.m +++ b/tbx/testext/Contents.m @@ -1,5 +1,5 @@ % Test Framework Extensions -% Version 1.0.5 (R2026a) 16-Jun-2026 +% Version 1.0.6 (R2026a) 13-Jul-2026 % % Constraints % @@ -20,5 +20,9 @@ % PreferenceFixture % SimulinkModelFixture % SuppressParpoolAutocreateFixture +% +% Alias +% +% Testable % Copyright 2026 The MathWorks, Inc. \ No newline at end of file diff --git a/tbx/testext/Testable.m b/tbx/testext/Testable.m new file mode 100644 index 0000000..a59c7ac --- /dev/null +++ b/tbx/testext/Testable.m @@ -0,0 +1,4 @@ +classdef Testable < matlab.uitest.TestCase + %TESTABLE Convenience alias for matlab.uitest.TestCase. + +end % classdef \ No newline at end of file diff --git a/tbx/testextdoc/Changelog.md b/tbx/testextdoc/Changelog.md index 1791d88..f169d89 100644 --- a/tbx/testextdoc/Changelog.md +++ b/tbx/testextdoc/Changelog.md @@ -1,5 +1,9 @@ # Release notes +## Version 1.0.6 + +* Added `Testable` alias + ## Version 1.0.5 * Added support for `code font` in release notes diff --git a/tbx/testextdoc/Testable.md b/tbx/testextdoc/Testable.md new file mode 100644 index 0000000..3984b70 --- /dev/null +++ b/tbx/testextdoc/Testable.md @@ -0,0 +1,88 @@ +# `Testable` + +Convenience alias for +[`matlab.uitest.TestCase`](https://www.mathworks.com/help/matlab/ref/matlab.uitest.testcase-class.html). + +## Overview + +`Testable` is a thin subclass of `matlab.uitest.TestCase`. It does not +add behavior, properties, or methods. Its purpose is to make UI test +classes shorter and easier to read. + +Use `Testable` when you want the full UI testing API provided by +`matlab.uitest.TestCase`, including methods such as `press`, +`choose`, `type`, and `drag`. + +## Example + +```text +classdef tMyButton < Testable + + methods ( Test ) + + function tPressButton( testCase ) + clicked = false; + fig = uifigure(); + testCase.addTeardown( @() delete( fig ) ) + + btn = uibutton( fig, ... + "Text", "Run", ... + "ButtonPushedFcn", @(~,~) onPress() ); + + testCase.press( btn ) + + testCase.verifyTrue( clicked ) + + function onPress() + clicked = true; + end + + end + + end + +end +``` + +## Notes + +- `Testable` is functionally equivalent to subclassing + `matlab.uitest.TestCase` directly. +- Use `matlab.unittest.TestCase` instead when the test does not require + UI interaction helpers. + +## Testing UI Properties + +When a UI class needs to expose handles for UI tests, keep those +properties read-only to production code and grant read access to +`Testable` subclasses. + +```text +classdef MyView < matlab.ui.componentcontainer.ComponentContainer + + properties ( GetAccess = ?Testable, SetAccess = private ) + Button(:, 1) matlab.ui.control.Button {mustBeScalarOrEmpty} + Grid(:, 1) matlab.ui.container.GridLayout {mustBeScalarOrEmpty} + end + + methods ( Access = protected ) + + function setup( obj ) + obj.Grid = uigridlayout( obj, [1 1] ); + obj.Button = uibutton( obj.Grid, "Text", "Run" ); + end + + end + +end +``` + +This pattern lets UI tests inspect or interact with internal handles +while avoiding a wider public API. It also keeps mutation inside the +component implementation by pairing `GetAccess = ?Testable` with +`SetAccess = private`. + +## See Also + +- [`matlab.uitest.TestCase`](https://www.mathworks.com/help/matlab/ref/matlab.uitest.testcase-class.html) +- [`matlab.unittest.TestCase`](https://www.mathworks.com/help/matlab/ref/matlab.unittest.testcase-class.html) diff --git a/tbx/testextdoc/helptoc.md b/tbx/testextdoc/helptoc.md index b8ad672..bc21d6d 100644 --- a/tbx/testextdoc/helptoc.md +++ b/tbx/testextdoc/helptoc.md @@ -17,4 +17,6 @@ * [GridLayoutFixture](GridLayoutFixture.md) * [PreferenceFixture](PreferenceFixture.md) * [SimulinkModelFixture](SimulinkModelFixture.md) - * [SuppressParpoolAutocreateFixture](SuppressParpoolAutocreateFixture.md) \ No newline at end of file + * [SuppressParpoolAutocreateFixture](SuppressParpoolAutocreateFixture.md) + * [Alias]() + * [Testable](Testable.md) diff --git a/tbx/testextdoc/index.md b/tbx/testextdoc/index.md index e7dc775..ca1c817 100644 --- a/tbx/testextdoc/index.md +++ b/tbx/testextdoc/index.md @@ -20,4 +20,7 @@ The Test Framework Extensions toolbox provides custom [constraints](https://www. * [`SimulinkModelFixture`](PreferenceFixture.md) - load a Simulink model and close it on teardown. * [`SuppressParpoolAutocreateFixture`](SuppressParpoolAutocreateFixture.md) - suppress the automatic creation of parpools and restore the original setting in teardown. +### Alias +* [`Testable`](Testable.md) - alias for `matlab.uitest.TestCase` + The documentation provides examples of how to use these constraints and fixtures. \ No newline at end of file