MATLAB: How to construct test cases derived from the matlab.unittest.TestCase class for private methods in MATLAB 8.1 (R2013a)

MATLABmethodoopprivateunittest

I would like to construct test cases derived from the matlab.unittest.TestCase class for private methods. How do I do this?

Best Answer

In MATLAB, you can specify the classes that are allowed to access a private method in the 'Access' attribute statement. Suppose MyTestCase is derived from the matlab.unittest.TestCase class in the following example:
methods( Access = ?MyTestCase )
function obj = objMethod(obj)
%do something
end
end
This allows MyTestCase to access the private method objMethod.