I am unable to run the tests for my DAOImpl class using @RunWith(SpringJUnit4ClassRunner.class) & getting following exception: No such method exception Following is my repository-test.xml located under "WebContent/WEB-INF/spring/"
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:mvc="http://ift.tt/1bHqwjR"
xmlns:context="http://ift.tt/GArMu7"
xsi:schemaLocation="
http://ift.tt/GArMu6 http://ift.tt/QEDs1e
http://ift.tt/GArMu7 http://ift.tt/QEDs1k
http://ift.tt/1bHqwjR http://ift.tt/1bVJL9q">
<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="br.com.braziljs.loiane" />
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />
<!-- misc -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
<property name="url"><value>jdbc:mysql://localhost/braziljs</value></property>
<property name="username"><value>root</value></property>
<!-- <property name="password"><value>root</value></property>-->
</bean>
<!-- Configures Hibernate - Database Config --> <!-- import resource="db-config.xml" /> -->
</beans>
And my Spring Test class is as follows:
package br.com.braziljs.loiane.test;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import javax.sql.DataSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
//import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import br.com.braziljs.loiane.dao.DeviceDAO;
import br.com.braziljs.loiane.model.MIDevice;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("/WEB-INF/spring/repository-test.xml")
public class TestDeviceDao {
/* @Autowired
private WebApplicationContext webApplicationContext;*/
@Before
public void setUp() {
// this.deviceRepository = new DeviceDAO(ds);
System.out.println("inside setup");
}
/*
@Autowired
private DeviceDAO deviceRepository;
@Autowired
private DataSource ds;
*/
@Test
public void test() {
// when(hibernateTemplate.get(Book.class, 1L)).thenReturn(new Book());
// final MIDevice device = deviceRepository.findByDeviceId(1L);
// verify(hibernateTemplate, times(1)).get(Book.class, 1L);
// assertNotNull(device);
// System.out.println(device);
System.out.println("inside setup");
}
}
Aucun commentaire:
Enregistrer un commentaire