This is a migrated thread and some comments may be shown as answers.

Asserting that return was called after condition met in void type method

1 Answer 56 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gerard
Top achievements
Rank 1
Gerard asked on 14 Oct 2016, 09:05 PM

In a method like

void ReturnIfObjectIsNull()
        {
            var obj = new SomeObject();
 
            if (obj == null)
                return;
 
            // Do other stuff..
        }

 

How do I assert that the early return fired (without asserting that the stuff that would have happened afterword never occurred).
Asserting the object is null is not enough. I would need to assert that he function returned early when the object was null.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Svetlozar
Telerik team
answered on 19 Oct 2016, 03:08 PM
Hi,

Thank you for your feedback!

I am sorry If I am missing something, but it is not really clear what you want to achieve. Currently I don't see how you can assert that a method has returned at an arbitrary place. I guess you could add empty DoNothing method before the return you are interested in and assert that it has been called. 

Regards,
Svetlozar
Telerik by Progress
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
Tags
General Discussions
Asked by
Gerard
Top achievements
Rank 1
Answers by
Svetlozar
Telerik team
Share this question
or