Page 1 of 1

This laboratory exercise engages you in unit testing-based development of a simple Java method. You don't need to be a J

Posted: Thu May 05, 2022 1:01 pm
by answerhappygod
This Laboratory Exercise Engages You In Unit Testing Based Development Of A Simple Java Method You Don T Need To Be A J 1
This Laboratory Exercise Engages You In Unit Testing Based Development Of A Simple Java Method You Don T Need To Be A J 1 (47.9 KiB) Viewed 33 times
This Laboratory Exercise Engages You In Unit Testing Based Development Of A Simple Java Method You Don T Need To Be A J 2
This Laboratory Exercise Engages You In Unit Testing Based Development Of A Simple Java Method You Don T Need To Be A J 2 (28.09 KiB) Viewed 33 times
This laboratory exercise engages you in unit testing-based development of a simple Java method. You don't need to be a Java expert to complete this exercise. Laboratory tasks: 1. Unit testing with JUnit for the method "Largest" in Largest.java class a. Create a new Java Project in Eclipse b. Add a new Java class "Largest.java" class (Largest.java class source code is in next page) in the project c. Add a JUnit Test Case "testLargest.java" in the project. Initial testLargest.java source code is in the next page d. Develop and execute the following unit tests for Largest.java, Add the following methods in testLargest.java and write assertion to verify 1. testPositives - testing a list of all positive integers 2. testNegatives - testing a list of all negative integers 3. testMixes - testing a list containing both positive and negative and zero values e. Some tests (d) should fail. This indicates Largest.java class has defect. Fix the defect and re-run tests. Report submission: Create a MS Word or PDF document containing the following: 1. Unit testing with JUnit a. Outputs of unit tests. Include both failed and passed unit tests. In the case of failed unit tests, indicate what was wrong and what was done to fix the problem. b. Final outputs of all unit tests showing successful pass for all c. Source code of final testLargest.java class d. Source code of final Largest.java class after making correction
Source Codes: ************* ******* public class Largest { public Largest() { } public int largest (int[] list) { int index; int max = 0; for (index = 0; index < list.length-1; index++) { if (list [index] > max) { max = list [index]; } } return max; } ********* import static org.junit.Assert. *; import org.junit. Test; public class TestLargest { private Largest temp1; @Test public void test() { test Positive (); // testNegative (); testMixes (); } public void testPositive(){ int[] arr = new int [5]; arr [0] = 8; arr [1] = 9; arr [2] = 7; arr [3] = 10; arr [4] = 2; Largest temp1 = new Largest (); int maxValue = temp1.largest (arr); /** add tests to check for this unit test **/ } public void testNegative(){ /** add tests to check for this unit test **/ } public void testMixes(){ /** add tests to check for this unit test **/ } } ******** *****