Use verifyCalled to check for only one input value?

2 ビュー (過去 30 日間)
Thomas Witkowski
Thomas Witkowski 2022 年 3 月 16 日
回答済み: Thomas Witkowski 2022 年 3 月 17 日
Is it possible to use verifyCalled in a unit test to verify that a function was called and that one of many parameters (e.g. the second only) is equal to a specifiy value? In all examples I can find either all parameter values are checked or none of them.

採用された回答

Thomas Witkowski
Thomas Witkowski 2022 年 3 月 17 日
I found at least one solution to it with using self defined constraint:
classdef IsAny < matlab.unittest.constraints.Constraint
methods
function is_satisfied = satisfiedBy(~, ~)
is_satisfied = true;
end
function diag = getDiagnosticFor(~, ~)
import matlab.unittest.diagnostics.StringDiagnostic;
diag = StringDiagnostic('IsAny passed.');
end
end
end
Using this, we can do things like
verifyThat(fooBar(IsAny(), Data, IsAny()), WasCalled)
to verify that fooBar has been called and second parameter equals Data, where the first and the last are ignored.
Is there a Matlab build-in solution to this?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMock Dependencies in Tests についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by