Testing the device Parallel .Foreach C #

I use JustMock for unit testing in C #. The problem I am facing, I can not approve the functions called inside Parallel.Foreach . However, the tasks done inside can be argued.

 Parallel.ForEach(aList, entity => { //Can be asserted using Assert(5,parameter.value) in the test parameter.value = 5; //Cannot be asserted, assertion fails Mock.Assert(parameter) in the test //is arranged using MustBeCalled parameter.call(); }) 

I found the same problem in other test cases. Is this justmock misbehaving?

+8
c # unit-testing justmock
source share
1 answer

With parallel processing, you cannot easily assume that something will or will not happen, which makes it more complex. Instead, you concentrate on signs that tell you that something is working. The problem here is that Parallel.ForEach stops processing as soon as an exception is noticed, while you expected it to process all elements. There is nothing wrong with your JustMock . Using regular foreach should solve this problem. if you have reason to use Parallel.ForEach anyway, try to catch all Exception Exceptions here.

+3
source share

All Articles