Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring + Mockito test injection
    primarykey
    data
    text
    <p>My question is very similar to the issue raised in <a href="https://stackoverflow.com/questions/2457239/injecting-mockito-mocks-into-a-spring-bean">Injecting Mockito mocks into a Spring bean</a>. In fact, I believe the accepted answer there might actually work for me. However, I've got one issue with the answer, and then some further explanation in case the answer there is not in fact my answer.</p> <p>So I followed the link in the aforementioned post to the Springockito website. I altered my <code>test-config.xml</code> to include something similar to the following:</p> <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mockito="http://www.mockito.org/spring/mockito" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.mockito.org/spring/mockito http://www.mockito.org/spring/mockito.xsd"&gt; ... &lt;mockito:mock id="accountService" class="org.kubek2k.account.DefaultAccountService" /&gt; ... &lt;/beans&gt; </code></pre> <p>There seems to be something wrong with the <code>www.mockito.org</code> redirect currently, so I found the XSD code at <a href="https://bitbucket.org/kubek2k/springockito/raw/16143b32095b/src/main/resources/spring/mockito.xsd" rel="nofollow noreferrer">https://bitbucket.org/kubek2k/springockito/raw/16143b32095b/src/main/resources/spring/mockito.xsd</a> and altered the final entry in xsi:schemaLocation to point to this bitbucket link.</p> <p>Running <code>mvn test</code> then produced the following error (newlines added for readability):</p> <pre><code>Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 43 in XML document from class path resource [spring/test-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 43; columnNumber: 91; The prefix "mockito" for element "mockito:mock" is not bound. </code></pre> <p>So the question regarding Springockito is: Is it possible anymore to include this? What am I missing?</p> <p>Now, on to the further explanation...</p> <p>I have an interface whose implementation I'm trying to test:</p> <pre><code>public interface MobileService { public Login login(Login login); public User getUser(String accessCode, Date birthDate); } </code></pre> <p>The implementation contains a DAO that Spring <code>@Autowire</code>s in for me:</p> <pre><code>@Service public class MobileServiceImpl implements MobileService { private MobileDao mobileDao; @Autowired public void setMobileDao(MobileDao mobileDao) { this.mobileDao = mobileDao; } } </code></pre> <p>I don't want to alter my interface to include a <code>setMobileDao</code> method, because that would be adding code just to support my unit testing. I'm trying to mock out the DAO since the actual SUT here is the ServiceImpl. How can I achieve this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload