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
UPDATE: Please see the comment by Cherry for why the suggestion below is flawed. (Am keeping the answer on here rather than deleting as the comment may provide useful information to others as to why this doesn't work.)
Another option worth considering if using dependency injection (e.g. Spring) is @PostConstruct. This will guarantee dependency injection is complete, which wouldn't be the case in a constructor:
@PostConstruct
public void init() {
// One-time initialization...
}