0

I would like to know the right recommendation on below case

My application's business module (single assembly) has below folder structure

-Service (folder)

  - MyService.cs - Implements IMyService deals with service to be performed

-DomainModel (folder)

  - MyDomainModel.cs - only deals with pure business rules and completely isolated from any infrastructure code. (its a normal class and is not decoupled via any interface)

Scenario is I need to test MethodA in MyService.cs, internally it calls DomainMethodA in MyDomainModel.cs

So here, do I need to Shim DomainMethodA?

Thanks

Johan429
  • 3
  • 4
  • 1
    you need to work on your question, sounds like you want to ask how to test between seperate modules. Get your question title correct – Keith Nicholas Mar 30 '17 at 05:20

1 Answers1

0

Basically when we talk about unit testing we are testing the unit. The unit in this case is small piece of functionality, for example, a method. And in case of unit testing we don't want to go away from this method (at least not to another module/class), thus all other parties should be mocked. So, in your case MyDomainModel should be mocked.

Another case is when we talk about integration testing. In this case we don't want to mock anything, but want the test how application goes through the long sequence of several different modules and classes. Sometimes/quite often it is complicated to check and verify all the results of the middle parts of the sequence, thus in this case it is better to create unit tests for this parties.

I would advice to combine both of this testing types/styles.

Rufi
  • 2,529
  • 1
  • 20
  • 41
  • I can see msdn recommendation as, "Use shims to isolate your code from assemblies that are not part of your solution.". In the above case both classes are in the same assembly which is why the confusion. Ref.https://msdn.microsoft.com/en-in/library/hh549176.aspx?f=255&MSPPError=-2147217396. – Johan429 Mar 30 '17 at 05:34
  • Maybe it is good to clarify the difference between mocks and shims, have a look here: http://stackoverflow.com/questions/28325053/difference-between-shims-and-stubs – Rufi Mar 30 '17 at 05:59
  • In the above case mock/stub is not possible since MyDomainModel is not decoupled via any interface. Its a normal class. So here only possibility is call detouring like shim. – Johan429 Mar 30 '17 at 06:11