Unit test with several data sets

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Hypothesis Tests 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by