Results 1 to 7 of 7
Thread: Mock object behaviour
- 09-11-2013, 06:30 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 52
- Rep Power
- 0
Mock object behaviour
Hi All,
I am creating mock object for my service to test my Spring MVC controller. This service used some proxies for getting the results. Now my question is do I have to mock these proxies too in test class? I am getting error like
Java Code:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.myproject.MyProxy] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
Java Code:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @WebAppConfiguration public class MyControllerTest { private MockMvc mockMvc; @Mock private MyService myService; .......................................... }
- 09-11-2013, 06:44 PM #2
Re: Mock object behaviour
What happened when you tried?
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 09-11-2013, 06:55 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Mock object behaviour
Just to be clear, where are these proxies?
Are they part of the service you are mocking?
Then I would be surprised if you were expected mock out things that aren't actually going to be called.Please do not ask for code as refusal often offends.
** This space for rent **
- 09-11-2013, 07:14 PM #4
Member
- Join Date
- Dec 2010
- Posts
- 52
- Rep Power
- 0
Re: Mock object behaviour
In MyService I have
Java Code:@Resource MyProxy myProxy; public void doSomething() { String resp = myProxy.getResponseStatus(); }
- 09-12-2013, 11:03 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Mock object behaviour
So something else is wrong if Spring is looking to inject a proxy into a mock object.
Now, it's possible Spring is simply going to load everything anyway, which would include your "real" MyService, in which case there should be a MyProxy somewhere.
After all, you'll need one in real life.
But I would hope for testing it wouldn't require that.Please do not ask for code as refusal often offends.
** This space for rent **
- 09-12-2013, 04:29 PM #6
Member
- Join Date
- Dec 2010
- Posts
- 52
- Rep Power
- 0
Re: Mock object behaviour
Do I have to add beans in test context defination file? Right now in MyControllerTest-context.xml I have
Java Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <mvc:annotation-driven /> </beans>
- 09-12-2013, 04:37 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Similar Threads
-
Java Native Access (JNA) to Windows DLL behaviour does not match C Exe behaviour.
By comsci in forum Advanced JavaReplies: 1Last Post: 12-12-2012, 09:43 PM -
Please help me with Mock Objects.
By fatabass in forum New To JavaReplies: 1Last Post: 09-12-2012, 02:27 AM -
develop mock ups
By karthikeyan_raju in forum NetBeansReplies: 0Last Post: 10-19-2009, 04:58 PM -
800 Mock Questions for SCJP 1.6
By Enthuware in forum Java SoftwareReplies: 2Last Post: 01-16-2008, 12:57 PM
Bookmarks