This exercise is about getting familiar with unit testing and JUnit 5 approach in particular.
- Design and code a
factorialmethod in the Factorial class. Here are some details:
- the method takes a String as a parameter, transforms it to an integer value and counts its factorial.
- The method returns a result as a String.
- String parameter
nmust represent a non-negative integer number. If it does not, throw an IllegalArgumentException.
- Complete the test classes:
- FactorialBadInputTesting
There are four empty methods that you must complete:testNullInput- test a null input casestestNegativeInput- test a negative number input casestestFractionalInput- test a fractional casestestNonDigitalInput- test a non-digit cases
- FactorialCsvParametrizedTesting
it is a parameterized test, that takes arguments from the csvCases.csv file. Do not change the csv file, only implement the method. - FactorialMethodSourceParametrizedTesting
it is a parameterized test, that takes arguments from thetestCasesmethod. You must complete the test method and introduce thetestCasesmethod, that provides following cases:- "1", "1"
- "2", "2"
- "5", "120"
- FactorialRegularInputTesting
it is a test class where you can add regular test cases. Consider covering cases that are not present in other test classes.
To pass the exercise, your tests must correctly detect flaws of some other implementations. There are special tests in several classes that apply your tests to your and other problematic("bad") implementations:
- FactorialTestingsTest
- LazyFactorialTestingsTest
- WrongOperationConcatIntFactorialTestingsTest
- WrongOperationSumIntFactorialTestingsTest
Your solution method must pass your tests while other implementation must fail your tests in some cases.
Also, there is one more secret test class that you do not have access to. It will be applied to your solution once you submit it to Autocode. So, consider the variety of possible cases.
Hint: Factorial reference