Last active
November 5, 2016 15:39
-
-
Save duck8823/1bc80dbd73f3396449fe66a6272a7d96 to your computer and use it in GitHub Desktop.
DBUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<dataset> | |
<User id="1" name="foo" /> | |
<User id="2" /> | |
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<dataset> | |
<User id="1" name="{null}" /> | |
<User id="2" name="foo" /> | |
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<dataset> | |
<User id="1" /> | |
<User id="2" name="foo" /> | |
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@SpringBootTest | |
public class DBUnitTest { | |
@Autowired | |
private DataSource dataSource; | |
@Before | |
public void test() throws SQLException, DatabaseUnitException { | |
DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); | |
IDataSet iDataSet = new FlatXmlDataSetBuilder().build(getClass().getResourceAsStream("/data_with_null.xml")); | |
ReplacementDataSet replacementDataSet = new ReplacementDataSet(iDataSet); | |
replacementDataSet.addReplacementObject("{null}", null); | |
DatabaseOperation.CLEAN_INSERT.execute(connection, replacementDataSet); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@SpringBootTest | |
@TestExecutionListeners({ | |
DependencyInjectionTestExecutionListener.class, | |
DbUnitTestListener.class | |
}) | |
public class DBUnitTest { | |
@DataSet("/test.xml") | |
@Test | |
public void test() { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@SpringBootTest | |
public class DBUnitTest { | |
@Autowired | |
private DataSource dataSource; | |
@Before | |
public void test() throws SQLException, DatabaseUnitException { | |
DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); | |
IDataSet iDataSet = new FlatXmlDataSetBuilder().build(getClass().getResourceAsStream("/data.xml")); | |
DatabaseOperation.CLEAN_INSERT.execute(connection, iDataSet); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment