Unit test with several data sets

7 ビュー (過去 30 日間)
Maia
Maia 2018 年 4 月 16 日
コメント済み: Maia 2018 年 4 月 16 日
Hi,
Suppose I'd like to write unit test for an image segmentation function. I'd like to know how would you perform unit tests with several data sets (i.e., testing that single function on several image samples, which have different expected values).
I tried these codes, but I am not sure if this is the way to go (especially the for ... end). Also, I want to track for which image the test didn't pass, but verifyEqual does not return a value to test that.
So far, I created a subfolder for each image test where I put data like expected value for that image.
for iCase = 1:length(testCase.TestData.data)
data = testCase.TestData.data(iCase); % read/load the current data, with the expected value for the current image sample
actSol = functionToBeTested(); % computed value
expSol = data.value; % expected value
verifyEqual(testCase, actSol, expSol);
end
I found this solution in 2014:
I don't know if this is an appropriate approach for me.
Thank you,

採用された回答

Andy Campbell
Andy Campbell 2018 年 4 月 16 日

Hello Maia,

It sounds like you may be interested in leveraging parameterized testing. This is useful when the test content is that same and the only thing that changes is the data. Parameterized testing allows you to remove the for-loop and create a new test element for each data combination. Steve even blogged about using the technique to test all the the examples in one of his books.

Hope that helps! Andy

  1 件のコメント
Maia
Maia 2018 年 4 月 16 日
Hello Andy,
Thank you a lot for the two links. That's exactly I want.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHypothesis Tests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by