Are there any best practices to get Junit execute a function once in a test file , and it should also not be static.
like @BeforeClass
on non static fun
The article discuss 2 very nice solutions for this problem:
A simple if statement seems to work pretty well too:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
public class myTest {
public static boolean dbInit = false;
@Autowired
DbUtils dbUtils;
@Before
public void setUp(){
if(!dbInit){
dbUtils.dropTables();
dbUtils.createTables();
dbInit = true;
}
}
...