Quantcast
Channel: Spring beans redefinition in unit test environment - Stack Overflow
Browsing latest articles
Browse All 14 View Live

Answer by luboskrnac for Spring beans redefinition in unit test environment

You do not need to use any test contexts (doesn't matter is XML or Java based). Since Spring boot 1.4 there is available new annotation @MockBean which introduced native support for mocking and Spying...

View Article



Answer by Michael Wiles for Spring beans redefinition in unit test environment

Since the OP this has come along: Springockito

View Article

Answer by Sergey Grigoriev for Spring beans redefinition in unit test...

spring-reinject is designed to substitute beans with mocks.

View Article

Answer by Ev0oD for Spring beans redefinition in unit test environment

See this tutorial with @InjectedMock annotationIt saved me a lot of time. You just use @MockSomeClass mockedSomeClass@InjectMockClassUsingSomeClass service@Beforepublic void setUp() {...

View Article

Answer by for Spring beans redefinition in unit test environment

I don't have the reputation points to pile on duffymo's answer, but I just wanted to chime in and say his was the "right" answer for me.Instantiate a FileSystemXmlApplicationContext in your unit test's...

View Article


Answer by Daniel Alexiuc for Spring beans redefinition in unit test environment

There are some very complicated and powerful solutions listed here.But there is a FAR, FAR simpler way to accomplish what Stas has asked, which doesn't involve modifying anything other than one line of...

View Article

Answer by Michael Wiles for Spring beans redefinition in unit test environment

I want to do the same thing, and we're finding it essential.The current mechanism we use is fairly manual but it works.Say for instance, you wish to mock out bean of type Y. What we do is every bean...

View Article

Answer by krosenvold for Spring beans redefinition in unit test environment

One of the reasons spring is described as test-friendly is because it may be easy to just new or mock stuff in the unit test.Alternately we have used the following setup with great success, and I think...

View Article


Answer by Michael Pralow for Spring beans redefinition in unit test environment

I would propose a custom TestClass and some easy rules for the locations of the spring bean.xml:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations =...

View Article


Answer by toolkit for Spring beans redefinition in unit test environment

You can also write your unit tests to not require any lookups at all:@ContextConfiguration(locations = { "classpath:/path/to/test-config.xml" })@RunWith(SpringJUnit4ClassRunner.class)public class...

View Article

Answer by duffymo for Spring beans redefinition in unit test environment

You can use the import feature in your test app context to load in the prod beans and override the ones you want. For example, my prod data source is usually acquired via JNDI lookup, but when I test I...

View Article

Answer by Il-Bhima for Spring beans redefinition in unit test environment

Perhaps you could use qualifiers for your beans? You would redefine the beans you want to mock up in a separate application context and label them with a qualifier "test". In your unit tests, when...

View Article

Answer by cletus for Spring beans redefinition in unit test environment

Easy. You use a custom application context for your unit tests, or you don't use one at all and you manually create and inject your beans.It sounds to me like your testing might be a bit too broad....

View Article


Spring beans redefinition in unit test environment

We are using Spring for my application purposes, and Spring Testing framework for unit tests. We have a small problem though: the application code loads a Spring application context from a list of...

View Article
Browsing latest articles
Browse All 14 View Live




Latest Images