Reputation: 4695
Is there any way to ensure that some code is run at startup regardless of what entry point the program uses?
For example, my program has some code in a static initializer of its main entry point that checks that assertions are enabled. We had uncaught bugs a bit back because the integration test was being run without assertions enabled. The static initializer didn't catch this because it's only run when that particular class is loaded.
So is there any way to make a "program initializer": code that is always run when the program starts?
I could make some static method that each entry point has to call, but that means every single test would have to call it too (since each unit test is an entry point). That seems rather messy (easy to forget to add it, adds a lot of clutter, etc).
Is there a better solution?
Upvotes: 0
Views: 156
Reputation: 8318
You can use something like a @BeforeClass, which is like a static initializer for your test class. It'll be run once in the very beginning before everything else.
Upvotes: 1