Q:

SetUp, initialize Junit testing

I am trying to test my 3 classes that sorts string arrays in different ways!
I know that there is a method that initialize an array and then uses them in every single of my tests.
So far this is my code:
public class SortingTest {

    public insertionSort is = new insertionSort();
    public bubbleSort bs = new bubbleSort();
    @Test
    public void testBubbleSort() {
        String [] sortedArray ={"Chesstitans", "Ludo", "Monkey", "Palle"};
        bs.sort(sortedArray);
        assertArrayEquals(sortedArray, x);
    }
    @Test
    public void testInsertionSort() {

    }
    @Test
    public void testMergeSort() {

    }
    @Test
    public void testSelectionSort() {

    }
    @Before
    protected void setUp() throws Exception{
        String[]x ={"Ludo", "Chesstitans", "Palle", "Monkey"};
    }
}

Eventhough I have tried both setUp and initialize method it doesn't seem to find x what have I done wrong?

A:

You need to make x a member variable of the class SortingTest
public class SortingTest {  

    private String[] x; 

    @Before
    public void init() {
      x = new String {"Ludo", "Chesstitans", "Palle", "Monkey"};
    }
}

