Question: JUNIT Write unit tests for the sorting algorithm below. * Write 3 black box tests* from any of the following: Non functional technique or Boundary

JUNIT

Write unit tests for the sorting algorithm below. *Write 3 black box tests* from any of the following: Non functional technique or Boundary value analysis or Equivalence partition technique.

BubbleSort

public class BubbleSort {

// From: https://www.javatpoint.com/bubble-sort-in-java

public static void sort(int[] arr) {

int n = arr.length;

int temp = 0;

for(int i=0; i < n; i++){

for(int j=1; j < (n-i); j++){

if(arr[j-1] > arr[j]){

//swap elements

temp = arr[j-1];

arr[j-1] = arr[j];

arr[j] = temp;

}

}

}

}

public static void main(String args[]) {

// Transform args into int array. This is a demo, so if it crashes,

// that's on you.

int[] arr = new int[args.length];

for(int i = 0; i < args.length; i++)

arr[i] = Integer.parseInt(args[i]);

sort(arr);

for(int i : arr)

System.out.println(i);

}

}

**************************************************************************************************

Please use the file below to write the unit test:

import junit.framework.*;

public class SortTest extends TestCase

{

public SortTest( String name )

{

super( name );

}

// this is run before every test

protected void setUp()

{

}

// this is run after every test

protected void tearDown()

{

}

// This guy adds *all* of the tests of this class to the test suite

// (uses reflection)

public static Test suite()

{

return new TestSuite( SortTest.class );

}

// Your tests should start with the word test

public void test_this_is_a_sample_passing_test()

{

// Arrange

// Act

// Assert

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!