Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote