I have test:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestRepositoryConfig.class})
@Transactional
public class ServiceTest {
@Autowired
private UserRepository userRepository;
@Autowired
private Service service;
static {
initTestUser();
}
public void setUp() {
userRepository.seve(testUser);
}
public void test1() { ... }
public void test2() { ... }
I need first start method setUp, saving testUser, then start methods test1 and test2. Method setUp must performed only once! How can do it?
I believe the problem you are trying to solve should be done in a different way. As far as I see you want to fill your DB with some test data, and this is better to do in a global configuration for all tests.
But if you want to stick to your initial idea you can try an approach with listeners described in this blog post.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments