So I need to test how long it takes to get the kth element from sorted arrays of varying order. I would expect the run time to be O(N), but instead it seems to be growing more like O(2^N). This indicates to me that J-Unit is timing my setup() function even though it is annotated with @Before. What am I doing wrong?
import org.junit.Before;
import org.junit.Test;
public class GetKthTest {
int[] sorted1;
BubbleSort sort = new BubbleSort();
private int k = 50;
@Before
public void setUp() {
RandomListGen gen1 = new RandomListGen(80000);
sorted1 = sort.sort(gen1.getArray());
}
@Test
public void hundredThous() {
System.out.println(sorted1[k]);
}
}
Actually I don’t think you are doing anything wrong I think there is a bug in JUnit.
For reference I have almost the exact problem with
@AfterClassJUnit @AfterClass run time is added to a poor testcase 🙁.I have replicated your problem with generic code / JUnit4 in Eclipse.
Prints
,