问题
I tried to use to DbSetup to populate the database, but it did not work
class CommonOperations {
public static final Operation DELETE_ALL =
deleteAllFrom("ACH_GROUP");
public static final Operation INSERT_REFERENCE_DATA =
sequenceOf(
insertInto("ACH_GROUP")
.columns("ID", "CLOSED", "NAME", "OPENED", "COMPETENCE_ID", "LASTMODIFIEDDATE", "uuid") .values(1, "", "JAVA", "", 1, "", "") .build()); }
public class CompetenceDaoImplementationTest {
private static String username = "sa";
private static String password = "12345";
private static String URL = "jdbc:sqlserver://localhost:1433;databaseName=DB_Achi";
// the tracker is static because JUnit uses a separate Test instance for every test method.
private static DbSetupTracker dbSetupTracker = new DbSetupTracker();
@Before
public void prepare() throws Exception {
Operation operation =
sequenceOf(
CommonOperations.DELETE_ALL,
CommonOperations.INSERT_REFERENCE_DATA);
// without DataSource
DbSetup dbSetup = new DbSetup(new DriverManagerDestination(URL, username, password), operation);
// use the tracker to launch the DbSetup.
dbSetupTracker.launchIfNecessary(dbSetup);
}
@Test
public void testShowGroups() {
dbSetupTracker.skipNextLaunch();
}
来源:https://stackoverflow.com/questions/22990140/dbsetup-populate-the-database