I am trying to create a test that modifies a collection. The problem is that I do not know how to initialize the data for each call.
Suppose Test.DATA is a collection containing 200 items.
The test method deletes data based on the value of a.isTrue() .
I know that @Setup is similar to JUnit @Setup . I want to use @Before but I could not find it in JMH. How can I initialize data every time before calling the test method?
Thank you so much in advance.
@State(Scope.Thread) public class JavaCollectionBenchmark { List<Foo> cols; @Setup public void prepare(){ cols= new ArrayList<>(Test.DATA); } @Benchmark public long test(){ if(cols.size() != 200) { System.out.println("SECOND TIME DOESN'T WORK!"); System.exit(0); }else{ System.out.println("FIRST TIME"); } cols.removeIf(a-> a.isTrue()); return cols.size(); } }
source share