import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class PointTest {
private Point testPoint;
@BeforeEach
void setUp() throws Exception {
testPoint = new Point(5.0, 6.0);
}
@Test
void testToString() {
assertEquals("(5.0, 6.0)", testPoint.toString());
}
}
100% method coverage: testing code calls each method at least once.
No, but better than NOT having 100% method coverage.
JUnit assertion methods take an optional failure message:
100% statement coverage: testing executes every statement.
Better? Happy?
100% branch coverage: all outcomes are executed for each branch.
Good enough?
100% path coverage: testing exercises every possible path through the code.
@Test
public void testTotalCostSlowBad() {
assertEquals(0, Estimator.totalCost(false, false));
}
@Test
public void testTotalCostFastGood() {
assertEquals(15, Estimator.totalCost(true, true));
}
@Test
public void testTotalCostSlowGood() {
assertEquals(10, Estimator.totalCost(false, true));
}
@Test
public void testTotalCostFastBad() {
assertEquals(5, Estimator.totalCost(true, false));
}
|
Select the best option. This test class provides…
|
Select the best option. This test class..
/**
* Estimate the total cost of a job. The base cost is 0, requesting a fast
* job adds $5 to the cost, requesting a good job adds $10 to the cost.
*
* @param fast Does the customer want the job done fast?
* @param good Does the customer want the job done correctly?
* @return Estimate of the job cost in dollars.
*/
public static int totalCost(boolean fast, boolean good) {
Input | Expected Result |
---|---|
fast=false, good=false |
0
|
fast=true, good=false |
5
|
fast=false, good=true |
10
|
fast=true, good=false |
15
|
Open up a copy of LetterTest.java from PA1.
Take a minute to read over the tests then answer the following questions (privately) in the chat: