Question
Use Junit and Eclipse environment to finish the following questions. (15pts) Review the slides and add Junit library before running your tests. You need to
Use Junit and Eclipse environment to finish the following questions. (15pts)
Review the slides and add Junit library before running your tests. You need to create a new Project first, and then add the files.
Due date: November 6th, Monday. 11:59pm. Submit all screenshots of test result and test files.
1-Use the following code and write a test file called FactorialExceptionTest.java for the following factorial function. Test if it will throw an IllegalArgumentException exception if the parameter of the function is -3. (5pts)
/**
* Calculate the factorial of a number
*/
public class Factorial_1 {
public int factorial(int n) {
if (n < 0)
throw new IllegalArgumentException( "factorial cannot handle negative numbers!!" );
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
}
2-Write a parameterized test for the factorial function in question 1. Note: remember to import necessary packages. And your test class needs to test the factorial of four numbers: 3, 4, 2, 5 (5pts)
3-Write a test suite FactorialTest.java that includes the test files you wrote in question 1, and 2. (5pts)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started