Unit test with several data sets

14 views (last 30 days)
Maia
Maia on 16 Apr 2018
Commented: Maia on 16 Apr 2018
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,

Accepted Answer

Andy Campbell
Andy Campbell on 16 Apr 2018

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 Comment
Maia
Maia on 16 Apr 2018
Hello Andy,
Thank you a lot for the two links. That's exactly I want.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!