Skip to content

Instantly share code, notes, and snippets.

@schaloner
Created May 17, 2017 12:56
Show Gist options
  • Save schaloner/187f8c51609a58a70afbcdd24e3b881e to your computer and use it in GitHub Desktop.
Save schaloner/187f8c51609a58a70afbcdd24e3b881e to your computer and use it in GitHub Desktop.
Increasing test performance using TestContainers
package be.objectify.tcexample.db;
import be.objectify.tcexample.AbstractUserDaoTest;
import be.objectify.tcexample.UserDao;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.testcontainers.containers.PostgreSQLContainer;
import play.db.Database;
public class FasterJooqUserDaoTest extends AbstractUserDaoTest implements DbTestSupport,
TestData {
@ClassRule
public static PostgreSQLContainer postgres = new PostgreSQLContainer();
private Database database;
@Before
public void setup() throws Exception {
database = create(postgres);
loadTestData(database);
}
@After
public void tearDown() {
destroy(database);
}
@Override
public UserDao dao() {
return new JooqUserDao(database);
}
}
package be.objectify.tcexample.db;
import be.objectify.tcexample.AbstractUserDaoTest;
import be.objectify.tcexample.UserDao;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.testcontainers.containers.PostgreSQLContainer;
import play.db.Database;
public class JooqUserDaoTest extends AbstractUserDaoTest implements DbTestSupport,
TestData {
@Rule
public PostgreSQLContainer postgres = new PostgreSQLContainer();
private Database database;
@Before
public void setup() throws Exception {
// the database has all evolutions applied
database = create(postgres);
// load some test data
loadTestData(database);
}
@After
public void tearDown() {
destroy(database);
}
@Override
public UserDao dao() {
return new JooqUserDao(database);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment