I was annoyed to find in the Parameterized documentation that “when running a parameterized test class, instances are created for the cross-product of the test methods and the test data elements.” This means that the constructor is run once for every single test, instead of before running all of the tests. I have an expensive operation (1-5 seconds) that I put in the constructor, and now the operation is repeated way too many times, slowing the whole test suite needlessly. The operation is only needed once to set the state for all of the tests. How can I run several tests with one instance of a parameterized test?
I was annoyed to find in the Parameterized documentation that when running a parameterized
Share
I would move the expensive operation to a
@BeforeClassmethod, which should execute just once for the entire parameterized test.A silly example is shown below:
Will print: