I was told that Guice aims to create test code and is not needed in unit test. But how can I check Singleton (@Singleton) without using Guice?
In unit tests, you don’t need Guice (or any DI framework), the SUT is usually small enough for the manual DI to be good and good.
Now about how to "test a singleton." Similarly, you are testing any other class that is part of the beauty of singleton-as-a-scope. In your test methods, create a new instance of "singleton", test it, and then throw it away. Remember that you do not want the previous tests to influence the SUT, and you want to set different dependencies for each test, so the fact that you are using the scope and not the design pattern is good. You do not need to do anything to check it.
, , , DI, - , unit test. , , , . , "unit test" , . , .
, (, , !) Guice Spring DI.
Guice ( .) : , - DI .
, , : , . .
Guice injects dependencies, and you also need tests.Guice simplifies implementation changes for introduced classes to mimic objects (stubs, not real objects). Thus, your tests can run in a stub environment and be tested faster and independently of other levels of your application.
Source: https://habr.com/ru/post/1721377/More articles:Problem with binding to ASP.NET MVC model - asp.net-mvcIs it possible to use a common dictionary as a parameter for a method that expects an IDictionary - collectionsКак преобразовать веб-страницу в изображение в наборе инструментов javascript/Google - javascriptCan I generate a file in javascript and request a user download? - javascriptWhat to do with third-party Javadoc - javaGeneric type in C #: limiting the type of a parameter as a collection - collectionsHow to create groups of related types for use in C # generics if there is no `typedef`? - c ++Pressing input inside a text field does not fire the onclick event of the submit button in firefox - javascriptWhy are there conflicts with git rebase -p -i? - gitGenerics and anonymous classes (bug or function?) - javaAll Articles