Class-Based Unit Testing

7 次查看(过去 30 天)
Bahadir Erdenk
Bahadir Erdenk 2021-2-12
Hi!
I'm using MATLAB 2015b.
I want to create a class-based unit testing for a function like,
function y = multiply (x)
if x > 5
y = x * 2;
else
y = x * x;
end
end
and my unit test code is like that,
classdef testmultiply < matlab.unittest.TestCase
methods (Test)
function test_if_statement (testCase)
%...
end
end
end
here, I want to test the if statement for getting code coverage and also finding dead codes.
Actually, I'm able to test the multiply function with below code,
testCase.verifyEqual(y,x*2)
but, I want use an easier and more general way to test more complex functions. How can I do it in MATLAB 2015b?
Also, is there a way to unit test a Simulink Model in MATLAB 2015b without using Simulink Test, Polyspace Code Prover or something else?
Lastly, If anyone can provide me an source about unit test methods, I will be grateful.
Thanks in advance!
Bahadır

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Testing Frameworks 的更多信息

产品


版本

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by