Stubs Vs Shims Difference
Hello everybody,
today I want to mention difference between two kinds of testing. Shim vs Stub.
Take a look at the following code sample:
// Stub sample public interface IDependency { void SomeMethod(); } // Take note that class TestTarget allows to inject // interface IDependency public class TestTarget { private IDependency _dependency { get; set; } public TestTarget(IDependency dependency) { _dependency = dependency; } public void TestMethod() { _dependency.SomeMethod(); } } // Shim sample. Take note that class ShimTarget doesn't allow to inject // interface as dependency public class Dep : IDependency { public void SomeMethod() { } } public class ShimTarget { public void TestMethod() { Dep d = new Dep(); d.SomeMethod(); } }
Take note that class ShimTarget has dependency from class Dep. And you will not be able to mock this dependency with any mocking framework. But class TestTarget allows you to use plenty of mocking frameworks in order to unit test. And if you'll see class similar to ShimTarget then know, you'll most probably need Shims from Microsoft Fakes in order to unit test it.
Ready to take your Acumatica development to the next level? Whether you're working with stubs, shims, or tackling complex dependencies, customizing your Acumatica solution can streamline your processes and enhance your testing capabilities. If you’ve identified areas in your Acumatica environment that need tailored solutions, we’re here to help!
Leave a customization request today and let’s transform your Acumatica experience into a seamless, efficient, and fully optimized system. Your unique challenges deserve unique solutions—let’s build them together!