Does test3() need an assert statement? Why or why not? public class Test { priva
ID: 3907739 • Letter: D
Question
Does test3() need an assert statement? Why or why not?
public class Test {
private List list;
@Before public void setUp() {
list = new ArrayList();
}
@Test public void test1() {
list.add ("empanadas");
assertEquals ("[empanadas]", list.toString());
}
@Test public void test2() {
list.add ("dumpling");
list.add ("gnocci");
assertEquals ("[burrito, gnocci]", list.toString());
}
@Test (expected = NullPointerException.class)
public void test3() {
Min.min (list); // min() returns the min element
}
}
Explanation / Answer
Answer : Yes, we would require assert statement.
Explanation:
@Test(expected = NullPointerException.class)
It means that the function inside the test3 can return null pointer exception for which the test should not fail .
Min.min is the function inside test class for which we should add assert statement if the function correctly returned the min element.
So we need assert statement for it.
Thanks, Please let ms know if you have any doubts/concern.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.