![How to write unit test for a class with dependency to ServiceLocator (with example of Optimizely)?](/_next/image?url=%2Fstatic%2Fimages%2Fblog%2Fthumbs%2Funit_test_service_locator.jpg&w=384&q=50)
- Published on
Some testing classes may have a dependency to the ServiceLocator, so the dependencies are injected via property, for example. That makes class more difficult to unit test. In this post I will present how to write unit test for a class with dependency to ServiceLocator, with the real world example of Optimizely.