Is it good practice to use NSubstitute(or other testing frameworks that allow mocking) in the code(not in the tests)?

165 views
Skip to first unread message

anton tishchenko

unread,
Feb 14, 2019, 11:51:44 AM2/14/19
to NSubstitute

I faced with usage of NSubstitute inside business logic(outside of test classed):

var extension = Substitute.For<IExtension>();

I get used to utilization of NSubstitute inside test classes, when you need to mock some class(interface). But using NSubstitute outside of test classes confused me. Is it correct place for it? Is is correct to use NSubstitute like dependency injection container, that can create of instance of interface/class?

My concerns are that NSubstitute was designed to be used for tests. Performance inside tests is not very important thing, that is why it could be slow. Also, it relies on reflection, so it could not be very quick. But, is performance of NSubstitute poor, or is it ok?

Are there any other reasons, why NSubstitute or other mocking libraries should not be used outside of tests?

David Tchepak

unread,
Feb 14, 2019, 5:42:53 PM2/14/19
to nsubs...@googlegroups.com
Hi Anton,

I have previously written about this here: https://stackoverflow.com/a/53330171/906
I still stand by this answer! :)

Let me know if you need any additional information.
Regards,
David


--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nsubstitute...@googlegroups.com.
To post to this group, send email to nsubs...@googlegroups.com.
Visit this group at https://groups.google.com/group/nsubstitute.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages