I am running through some issues with Kentico's test libraries, I have installed Kentico Xperience Libraries Tests v13.0.94 and I have in a Test proyect some unit tests and some integration tests in different classes under different namespaces.
My issue is, when I run all the tests together I get the following error and the testing process stops:
Resolution of 'CMS.Core.IEventLogContextAccessor' failed with the following error: IoC container cannot be used for service resolution because it was not initialized yet. This means that the application was not properly pre-initialized or yet initialized. Use 'CMS.Core.Service.InitializeContainer' to perform container initialization.
These are the steps I have done for unit tests and integration tests:
- Unit tests: Every class inherits from UnitTests CMS class, we need this in order to create Fakes() and tests some methods without needing database entries for repositories.
- Integration Tests: We start a TestServer class, a Microsoft.AspNetCore.TestHost class that allows us to use an HttpClient and test different aspects of the application from start to finish.
When I execute any of these tests separately they work fine, but when I test them together I have the previous error. I tried to execute CMS.Core.Service.InitializeContainer() before any test but it seems that the test server and the UnitTest class both put dependencies in the Ioc container and cause issues when an unit test starts.
¿Is there any way to avoid this? ¿Do I need to separate the integration test in an isolated proyect?