Unplanned
Last Updated: 05 Jun 2019 11:59 by ADMIN
Kim
Created on: 09 Feb 2019 11:28
Type: Feature Request
1
Mock.Raise fails for mocks created on other threads

Hi I have encountered what I think is a bug.

I would expected the following unit test to pass. It does not.

The example is distilled from a more complex case.

Is it not supported to have other threads create mocks?

[Fact] public async Task Fails() { var iTask = Task.Run(() => Mock.Create<I>()); var i = await iTask; EA expectedArgs = new EA(); EA receivedArgs = null; i.Done += (sender, ea) => receivedArgs = ea;

i.Raise(x => x.Done += null, expectedArgs); Assert.Equal(expectedArgs, receivedArgs); } public class EA : EventArgs { } public interface I { event EventHandler<EA> Done; }


5 comments
ADMIN
Mihail
Posted on: 05 Jun 2019 11:59
Hello Kim,

Thank you for the additional information. It is always helpful to know more about the exact scenario before implementing a solution.

Regards,
Mihail
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Kim
Posted on: 04 Jun 2019 20:37

I'm using it for acceptance testing (ATDD/BDD), which means that nearly the entire application gets instantiated when running tests. Additionally, the instantiation is multithreaded, which is why some mock objects end up being created on different threads.

Most other mocking frameworks supports it. I have tried Moq and now reverted to use NSubstitute.

ADMIN
Mihail
Posted on: 14 Feb 2019 08:30
Hi Kim,

Thank you for the additional information it was useful.

Regarding your comment about whether this issue is a bug or a feature, JustMock is currently designed to handle scenarios where the test method and the creation of the mock objects are done in the same thread. The arrangement and the actual work could be on another thread, but not the execution of the test method and the creation of the mock object. This is why in our understanding this is a feature request.

Regards,
Mihail
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Kim
Posted on: 12 Feb 2019 14:59

Hi Mihail,

Thanks for you reply. 

I'm using it for acceptance testing, which means the entire system except some system boundaries are instanciated and some parts of the system are created on other threads. I was using NSubstitute before where this worked, but had another unrelated motivation for going towards JustMock.

I'm not sure I would agree completely with classifying it as a new feature rather than a bug. The behavior is not consistent.

For example, it works to create a mock on another thread and then arrange it.

 

ADMIN
Mihail
Posted on: 12 Feb 2019 11:22
Hello Kim,

JustMock does not support creating the mock object in a different thread. This is why I will change the type of this item to feature request.
Could you provide more detailed information on why your scenario requires the mock objects to be created in a separate thread? I am asking this so we can have a better understanding of your case when we start implementing it.

  
Regards,
Mihail
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items