When i start the test i have this NoSuchTableException. Do i need to set the same name of in-memory data base like that in production ?
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class }) @DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "login.xml") public class LoginControllerTest { private MockMvc mockMvc; @Before public void setUp() { mockMvc = MockMvcBuilders.xmlConfigSetup("loginControllerTest-context.xml").build(); } @Test @ExpectedDatabase("login.xml") public void testShowForm() throws Exception { mockMvc.perform(get("/login")).andExpect(status().isOk()).andExpect(view().name("/login")) .andExpect(forwardedUrl("/WebContent/j/login.jsp")) .andExpect(model().attribute("form", hasProperty("id", nullValue()))) .andExpect(model().attribute("form", hasProperty("email", isEmptyOrNullString()))) .andExpect(model().attribute("form", hasProperty("username", isEmptyOrNullString()))) .andExpect(model().attribute("form", hasProperty("hostname", isEmptyOrNullString()))) .andExpect(model().attribute("form", hasProperty("pass", isEmptyOrNullString()))); } }
This here is loginControllerTest-context.xml
<?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" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <tx:annotation-driven transaction-manager="transactionManager" /> <context:component-scan base-package="com.profiles.controller.test" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property name="url" value="jdbc:hsqldb:mem:login" /> <property name="username" value="sa" /> <property name="password" value="" /> </bean> </beans>
This here is login.xml
<?xml version="1.0" encoding="UTF-8"?> <dataset> <person id="1" email="qwerty@asdf.com" username="qwerty" hostname="asdf.com" pass="password1234" /> <person id="2" email="zxcvb@asdf.com" username="zxcvb" hostname="asdf.com" pass="password1234" /> </dataset>
At last but not least Stack Trace
org.dbunit.dataset.NoSuchTableException: person at org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:288) at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:109) at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79) at com.github.springtestdbunit.DbUnitRunner.setupOrTeardown(DbUnitRunner.java:159) at com.github.springtestdbunit.DbUnitRunner.beforeTestMethod(DbUnitRunner.java:70) at com.github.springtestdbunit.DbUnitTestExecutionListener.beforeTestMethod(DbUnitTestExecutionListener.java:136) at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:277) at org.springframework.test.context.junit4.SpringMethodRoadie.runBefores(SpringMethodRoadie.java:315) at org.springframework.test.context.junit4.SpringMethodRoadie.runBeforesThenTestThenAfters(SpringMethodRoadie.java:253) at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:234) at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:204) at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:146) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:151) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) junit.framework.ComparisonFailure: table count expected:<[1]> but was:<[0]> at org.dbunit.assertion.JUnitFailureFactory.createFailure(JUnitFailureFactory.java:39) at org.dbunit.assertion.DefaultFailureHandler.createFailure(DefaultFailureHandler.java:105) at org.dbunit.assertion.DbUnitAssert.assertEquals(DbUnitAssert.java:237) at org.dbunit.assertion.DbUnitAssert.assertEquals(DbUnitAssert.java:205) at org.dbunit.Assertion.assertEquals(Assertion.java:104) at com.github.springtestdbunit.assertion.DefaultDatabaseAssertion.assertEquals(DefaultDatabaseAssertion.java:33) at com.github.springtestdbunit.DbUnitRunner.verifyExpected(DbUnitRunner.java:128) at com.github.springtestdbunit.DbUnitRunner.afterTestMethod(DbUnitRunner.java:80) at com.github.springtestdbunit.DbUnitTestExecutionListener.afterTestMethod(DbUnitTestExecutionListener.java:141) at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:340) at org.springframework.test.context.junit4.SpringMethodRoadie.runAfters(SpringMethodRoadie.java:351) at org.springframework.test.context.junit4.SpringMethodRoadie.runBeforesThenTestThenAfters(SpringMethodRoadie.java:262) at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:234) at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:204) at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:146) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:151) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
No comments:
Post a Comment