JUnit 4x Test Suite and Spring
Hi.
I've got multiple data providers in my web application. Each one effectively loads data from DBMS.
I need to apply something like SpringJUnit4ClassRunner but for test suite. How can I achieve this?
Here is sample code for unit test:
Code:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:testApplicationContext.xml" })
public class SecurityDataProviderTest {
private static HsqlDatabase database;
private static final int NORMAL_USER_ID = 10001;
private static final int DISABLED_USER_ID = 10002;
private static final int DELETED_USER_ID = 10003;
private static final int NOT_EXISTING_USER_ID = 10000;
private static final int ORGANIZATION_ID = 10001;
@Autowired
private SecurityDataProvider securityDataProvider;
@BeforeClass
public static void setUp() throws InstantiationException, IllegalAccessException,
ClassNotFoundException, SQLException, LiquibaseException {
database = new HsqlDatabase();
database.setUp("test");
}
@Test
public void getUser_UserExists_UserIsLoaded() {
User user = securityDataProvider.getUser(NORMAL_USER_ID);
Assert.assertNotNull(user);
Assert.assertEquals(NORMAL_USER_ID, user.getId());
Assert.assertEquals("John", user.getFirstName());
Assert.assertEquals("Doe", user.getLastName());
Assert.assertFalse(user.getIsDeleted());
Assert.assertFalse(user.getIsDisabled());
Organization organization = user.getOrganization();
Assert.assertNotNull(organization);
Assert.assertEquals(ORGANIZATION_ID, organization.getId());
}
So if I've got several data providers, I need to create test context for each of them. I'm expecting to init test context and database one time per suite and reuse it for several test classes
Please advise