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

1. In a Junit Test Case class, the method with notation @Before is executed befo

ID: 3699058 • Letter: 1

Question

1. In a Junit Test Case class, the method with notation @Before is executed before each test method. True or False?

2. Consider the following class Computation

public class Computation {

private int number1;

private int number2;

public Computation (int n1, int n2)

              number1 = n1;

              number2 = n2;

}

public int sum(){

              return number1 + number2;

}

public int difference(){

/* Math.abs(int)returns the absolute value of an int value. */

return Math.abs(number1-number2);

}

}

Complete the following Junit Test Case class Computation

public class ComputationTest{

               private Computation comp;

               @Before

               public void setup throws Exception

{

//TODO

}

@After

               public void teardown throws Exception

{

//TODO

}

Explanation / Answer

1) True 2) import org.junit.After; import org.junit.Before; public class ComputationTest { private Computation comp; @Before public void setup() throws Exception { comp = new Computation(1, 2); } @After public void teardown() throws Exception { comp = null; } }