Java – spring test Dbunit warning

I am using spring test Dbunit and receive a warning in my unit test:

Code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/context.xml"})
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class,TransactionalTestExecutionListener.class,DbUnitTestExecutionListener.class })
public class TestDB {

    @Autowired 
    private ICourseService courseService;

    @Test
    @DatabaseSetup("sampleData.xml")
    public void testFind() throws Exception {
        List<Course> courseList = this.courseService.getAllCourses();

        assertEquals(1,courseList.size());
        assertEquals("A001",courseList.get(0).getCourseNumber());
    }

}

Warning:

This problem can be solved when I use the following Dbunit without spring test Dbunit:

Connection jdbcConnection = DriverManager.getConnection( "jdbc:MysqL://localhost/test","root","root");
        IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
        connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,new MysqLDataTypeFactory());
        connection.getConfig().setProperty(DatabaseConfig.PROPERTY_MetaDATA_HANDLER,new MysqLMetadataHandler());

I don't know how to solve this problem in spring test Dbunit Please help.

Solution

The problem is solved

<property name="location">
        <value>classpath:jdbc.properties</value>
    </property> 
</bean>  

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${driver}" />
    <property name="url" value="${url}" />
    <property name="username" value="${username}" />
    <property name="password" value="${password}" />
</bean>

<bean id="sqlDataTypeFactory" class ="org.dbunit.ext.MysqL.MysqLDataTypeFactory" />

<bean id="dbUnitDatabaseConfig" class="com.github.springtestdbunit.bean.DatabaseConfigBean">
     <property name = "datatypeFactory" ref = "sqlDataTypeFactory" />
</bean> 
<bean id="dbUnitDatabaseConnection" class="com.github.springtestdbunit.bean.DatabaseDataSourceConnectionfactorybean">
    <property name="databaseConfig" ref="dbUnitDatabaseConfig"/>
    <property name="dataSource" ref="dataSource" />
</bean>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>