Qualification for checking objects with respect to an interface

3 visualizaciones (últimos 30 días)
Hau Kit Yong
Hau Kit Yong el 24 de Jul. de 2019
Respondida: Rajani Mishra el 13 de Mzo. de 2020
I want to write some tests to check if my objects have implemented an interface correctly. The outline of my test is as follows:
classdef ClassATest < matlab.unittest.TestCase
methods (Test)
function testAddOne(testCase)
% Example test function that uses the verifyEqual qualification.
testObj = ClassA();
testObj.Value = 1;
testObj.addOne();
testCase.verifyEqual(testObj.Value, 2);
end
function testImplementsInterfaceB(testCase)
% Checks that ClassA objects implement the InterfaceB interface.
% InterfaceB consists of an "addTwo" method.
% What qualification do I use here?
end
end
end
I've looked at the list of qualifications in Types of Qualifications, but am not able to find an appropriate method. It would be ideal if there is a method similar to Ruby's "assert_respond_to" method from the Minitest framework, as it makes the intent of the test clear and can itself serve as a form of "executable documentation".

Respuestas (1)

Rajani Mishra
Rajani Mishra el 13 de Mzo. de 2020
You can use function “ismethod” to check whether provided function is a method of object provided as an input argument and then use verifyTrue() on the output of this function.
To know more about “ismethod” function refer to this link : https://www.mathworks.com/help/matlab/ref/ismethod.html

Categorías

Más información sobre Write Unit Tests en Help Center y File Exchange.

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by