when I use @DatabaseSetup in the test.
there is an error "no such table" in the title case.
it's working collect below case.
CSV loader
public class CsvDataSetLoader extends AbstractDataSetLoader {
@Override
protected IDataSet createDataSet(Resource resource) throws Exception {
return new CsvDataSet(resource.getFile());
}
}
sql:
create table test
(
id int
);
table-ordering.txt
test
test.csv
id
1
2
3
test class
@SpringBootTest(classes = {TestConfig.class})
@RunWith(SpringRunner.class)
@DbUnitConfiguration(dataSetLoader = CsvDataSetLoader.class)
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class
})
@Transactional
public class JsonDatabaseTest {
@Autowired
JdbcTemplate jdbcTemplate;
@Test
@DatabaseSetup("/table/init")
public void test(){
System.out.println(jdbcTemplate.queryForList("select * from test"));
// printed out 1,2,3
}
}
but it's happened error 'no such table sh.test'
sql:
create schema sh;
create table sh.test
(
id int
);
table-ordering.txt
sh.test
sh.test.csv
id
1
2
3
test class
@SpringBootTest(classes = {TestConfig.class})
@RunWith(SpringRunner.class)
@DbUnitConfiguration(dataSetLoader = CsvDataSetLoader.class)
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class
})
@Transactional
public class JsonDatabaseTest {
@Autowired
JdbcTemplate jdbcTemplate;
@Test
@DatabaseSetup("/table/init") // if comment out this, no error occurs
public void test(){
System.out.println(jdbcTemplate.queryForList("select * from sh.test"));
}
}
When I comment out the code, no error occurs, so the table named "sh.test" must indeed exist.
but why is @DatabaseSetup missing the table? I can't guess.....
it was simply.
at setting class
at test class
Now I don't need to add the schema name to file names, etc.