I have this method and I am traying to do some data path testing , J unit test ,
ID: 3734449 • Letter: I
Question
I have this method and I am traying to do some data path testing , J unit test ,
this is how i was trying to do it but it keeps giving me an issue becuase is a void method insted of int
public void test() {
int [] arr = {3,5,7,8,2,1};
int size = 6;
int [] expected = {1,2,3,5,7,8};
assertArrayEquals(expected, bubbleSortEfficient.bubbleSortEfficientt(arr, size))
}
void bubbleSortEfficient(int A[], int size) int temp; bool exchanged true; for (int i = 0; i = i + 1 ; j-) if (AljlExplanation / Answer
As you have figured out the issue with unit testing of void method, there two ways to fix it -
1. Always return a value from the method, even if you do not use it. This is off-course helpful Unit testing.
2. Use the input data to verify the method with expected data.
I have showed both the approaches below followed by unit test cases. Proper description is also provided in the method/class/functions java doc.
BubbleSort.Java :
============
UNIT TEST CLASS :
===============