Go to this link https://www.guru99.com/junit-tutorial.html to learn about the basics, download, and install JUnit. The instructor will
Question:
- Go to this link https://www.guru99.com/junit-tutorial.html to learn about the basics, download, and install JUnit.
- The instructor will walk you through some JUnit test cases.
- You will then be asked to write some test cases on your own.
- Here are the starter files.
Calculation.java
public class Calculation {
//TestLogicTest - Test it in TestLogicTest.java
public static int findMax(int arr[]){
int max=arr[0];
for(int i=1;i
}
return max;
}
//cube - create a method that returns cube of a long. Test it in
TestLogicTest.java
//reverse - create a method that returns the reverse of a string. Test it in
TestLogicTest.java
}
TestLogicTest.java
import org.junit.Assert;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.BeforeClass;
import org.junit.AfterClass;
public class TestLogicTest {
/** Fixture initialization (common initialization
* for all tests). **/
@BeforeClass
public static void setUp() throws Exception {
System.out.println("Before class");
}
@Test
public void testFindMax(){
assertEquals(4,Calculation.findMax(new int[]{1,3,4,2}));
assertEquals(-1,Calculation.findMax(new int[]{-12,-1,-3,-4,-2}));
}
@Test
public void testCube(){
//Test cube here
}
@Test
public void testReverse(){
//Test reverse here
}
@AfterClass
public static void exit() throws Exception {
System.out.println("After class");
}
}
5. Review the starter files given above. Read the Junit tutorial and complete the TestLogicTest test cases. Submit the Calculation.java code and TestLogicTest.java to Canvas.
Auditing Cases An Interactive Learning Approach
ISBN: 978-0132423502
4th Edition
Authors: Steven M Glover, Douglas F Prawitt