Question: import static org.junit.jupiter.api.Assertions. * ; import org.junit.jupiter.api.AfterAll; import static java.time.Duration.ofMillis; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; / TODO: Write a test case (
import static org.junit.jupiter.api.Assertions.;
import org.junit.jupiter.api.AfterAll;
import static java.time.Duration.ofMillis;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
TODO: Write a test case following the examples above called nullPointerTest. This test will determine if the method Examples.getItemFromArray returns a null value
The method assertNull should help with this. It only takes one argument, the actual value.
The test will pass if the actual value is null and will fail otherwise.
Once you have created the test, do the following:
Test Examples.getItemFromArray what do you notice? Do the results match what you expect?
Test Examples.getItemFromArray what do you notice? Do the results match what you expect?
Test Examples.getItemFromArray what do you notice? Do the results match what you expect?
Test Examples.getItemFromArray what do you notice? Take a look at the Failure Trace
TODO: Write a test case called arrayIndexOutOfBoundsTest. This test will determine if the method Examples.getItemFromArray throws an ArrayOutOfBoundsException
The method assertThrows should help with this. For an example of how it works, check out the example below:
@Test
void numberFormatExceptionTest
Assertions.assertThrowsNumberFormatExceptionclass,
Integer.parseIntOne;
;
This test will pass if Integer.parseInt throws a NumberFormatException and will fail otherwise.
Your test should pass if Examples.getItemFromArray throws an ArrayIndexOutOfBoundsException and will fail otherwise.
Once you have created the test, do the following:
Test Examples.getItemFromArray what do you notice? Do the results match what you expect?
Test Examples.getItemFromArray what do you notice? Do the results match what you expect?
TODO: Write a test case called TimedTest. This test will determine if the method Examples.factorial executes faster than a specified time
The method assertTimeout should help with this. For an example of how it works, check out the example below:
@Test
void time
assertTimeoutofMillis What is the max acceptable execution time in milliseconds
Thread.sleep;
;
This test will pass if Thread.sleep finishes execution in under milliseconds.
Your test should pass if Examples.factorial executes in under milliseconds
Once you have created the test, do the following:
Test assertTimeoutofMillis and Examples.factorial what do you notice? Do the results match what you expect?
Test assertTimeoutofMillis and Examples.factorial what do you notice? Do the results match what you expect?
Examples.factorial has a design flaw... We don't want you to fix it just observe: Test assertTimeoutofMillis and Examples.factorial what do you notice? Do the results match what you expect?
TODO: Write a test case called InfiniteLoopTest. This test will decide if the method Examples.factorial executes far longer than it should.
The method assertTimeoutPreemptively should help with this. For an example of how it works, check out the example below:
@Test
void time
assertTimeoutPreemptivelyofMillis What is the max acceptable execution time in milliseconds If it goes beyond that point, it will fail it infinite loop or not!
Thread.sleep;
;
This test will pass if Thread.sleep finishes execution in under milliseconds.
Your test should pass if Examples.factorial executes in under milliseconds
Once you have created the test, do the following:
Test assertTimeoutofMillis and Examples.factorial what do you notice? Do the results match what you expect?
Test other combinations of values, note anything interesting you observe.
Now let's be clear here, it is impossible to programmatically test for an infinite loop. So why is this unit test appropriate for this case? Is it always appropriate? Did we just make a huge break through and be nominated for a Turing Award?
Step TODO: Uncomment this blocks of code and observe their behaviors
@AfterAll
static void print
Take a look at the annotation above @AfterAll
This performs after all tests!
System.out.printan awesome semester! ;
@BeforeAll
static void print
Take a look at the annotation above @BeforeAll
This performs before all tests!
System.out.printThank you all for ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
