错误
java org.junit.runner.JUnitCore TestCase
JUnit version 4.10
.E..
Time: 0.28
There was 1 failure:
1) testDbNoChanges(TestCase)
org.dbunit.dataset.NoSuchTableException: Did not find table 'EVENTS' in schema 'null'
问题
这个错误是什么意思?我究竟做错了什么?为什么架构为空?
第二个测试,实际测试一个表,通过了。这个测试应该只是测试数据库,但失败了。这些表都存在于之前和之后。
mysql> show tables;
+---------------+
| Tables_in_cal |
+---------------+
| events |
| guests |
| test |
+---------------+
3 rows in set (0.00 sec)
资源
我相信这是有用的片段,但一切都在https://bitbucket.org/djeikyb/simple_dbunit
36 public class TestCase
37 {
38
39 private IDatabaseTester database_tester;
40
41
42 public IDataSet getDataSet() throws FileNotFoundException, DataSetException
43 {
44 return new FlatXmlDataSetBuilder().build(
45 /*
46 new FileInputStream("src/simple_dbunit/expected_dataset.xml"));
47 new FileInputStream("dataset.xml"));
48 */
49 new FileInputStream("dataset.xml"));
50 }
51
52
53 @Before
54 public void setUp() throws Exception
55 {
56 database_tester = new JdbcDatabaseTester("com.mysql.jdbc.Driver",
57 "jdbc:mysql://localhost/cal",
58 "cal",
59 "cal");
60 database_tester.setDataSet(getDataSet());
61 database_tester.onSetup();
62 }
63
64 @Test
65 public void testDbNoChanges() throws Exception
66 {
67 // expected
68 IDataSet expected_data_set = getDataSet();
69
70 // actual
71 IDatabaseConnection connection = database_tester.getConnection();
72 IDataSet actual_data_set = connection.createDataSet();
73
74 // test
75 Assertion.assertEquals(expected_data_set, actual_data_set);
76 }
77
78 @Test
79 public void testTableNoChanges() throws Exception
80 {
81 // expected
82 ITable expected_table = getDataSet().getTable("test");
83
84 // actual
85 IDatabaseConnection connection = database_tester.getConnection();
86 IDataSet actual_data_set = connection.createDataSet();
87 ITable actual_table = actual_data_set.getTable("test");
88
89 // test
90 Assertion.assertEquals(expected_table, actual_table);
91 }
92
93 @Test
94 public void testTableNoChanges1() throws Exception
95 {
96 // expected
97 ITable expected_table = getDataSet().getTable("test");
98
99 // actual
100 IDatabaseConnection connection = database_tester.getConnection();
101 IDataSet actual_data_set = connection.createDataSet();
102 ITable actual_table = actual_data_set.getTable("test");
103
104 // test
105 Assertion.assertEquals(expected_table, actual_table);
106 }
107
108 }