Question: convert Tester class to JUnit testcase that uses asserts and multiple methods to test each scenario. Shell Junit testcase: import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.AfterAll; import
convert Tester class to JUnit testcase that uses asserts and multiple methods to test each scenario. Shell Junit testcase:
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class testing { @BeforeAll static void setUpBeforeClass() throws Exception { } @AfterAll static void tearDownAfterClass() throws Exception { } @BeforeEach void setUp() throws Exception { } @AfterEach void tearDown() throws Exception { } @Test void test() { int a = Something.random(); assertEquals(0, a); } }
The Tester class code:
public class Tester { public static void main(String[] args) { int[] a = new int[] { 5, 4, 1, 9, 2, 6 }; Arrays.swapLargestAndSmallest(a); System.out.println(java.util.Arrays.toString(a)); System.out.println("Expected: [5, 4, 9, 1, 2, 6]"); a = new int[] {1, 4, 1, 9, 2, 6}; Arrays.swapLargestAndSmallest(a); System.out.println(java.util.Arrays.toString(a)); System.out.println("Expected: [9, 4, 1, 1, 2, 6]"); a = new int[] {1, 4, 2, 9, 9, 6}; Arrays.swapLargestAndSmallest(a); System.out.println(java.util.Arrays.toString(a)); System.out.println("Expected: [9, 4, 2, 1, 9, 6]"); a = new int[] {1}; Arrays.swapLargestAndSmallest(a); System.out.println(java.util.Arrays.toString(a)); System.out.println("Expected: [1]"); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
