I am making some integration tests that load data into a remote test database before the integrations tests. However, it is a lot of data so I'd prefer to do it only once before all of my integrations tests.
I've gotten @BeforeClass/@AfterClass working with using either @RunWith(Suite.class) and JUnitCore.runClasses() to run all my test classes as a Suite. However, I am stuck on how to get Spring to Autowire resources that are needed for the setup and teardown. example:
public class AbstractTest {
@Autowired
private SessionFactory sf;
@BeforeClass
public static void setup() {
sf.getCurrentSession().createQuery("make tables");
}
}
But sf is always null, because @BeforeClass needs to be run from a static context. I have also tried using @ClassRule as shown here: How to share JUnit BeforeClass logic among multiple test classes but with no change;
How do I get both the @BeforeClass/@AfterClass functionality for a suite of test classes and have Autowired resources in the @BeforeClass/@AfterClass methods? Getting this to run with @Parameterized as well would be even better.