In: Computer Science
3. Given the test code below, what is the output to the console?
public class TestMe{
public TestMe(){
System.out.print(“a”);
}
public void setUp(){
System.out.print(“b”);
}
public void tearDown(){
System.out.print(“c”);
}
@Test
public void testX(){
System.out.print(“x”);
}
@Test
public void testY(){
System.out.print(“y”);
}
}
A. abxcbyc
B. abxcabyc
C. bxcbyc
D. abxyc
Answer: abcxy
Explanation:
Program:
Explanation:
Line 1:// Here taking class name as TestMe
Line 2: //Creating constructor for TestMe class
Line 3: // Here Printing this statement
Line 4: // End of constructor
Line 5://Start of method setUp()
Line 6:// Here Printing this statement
Line 7:// End of method setUp()
Line 8://Start of method tearDown()
Line 9:// Here Printing this statement
Line 10: // End of method tearDown()
Line 11://Comments
Line 12://Start of method testX()
Line 13:// Here Printing this statement
Line 14: // End of method testX()
Line 15://Comments
Line 16://Start of method testY()
Line 17:// Here Printing this statement
Line 18: // End of method testY()
Line 19:// Start of main()
Line 20:// Here creating the object for class TestMe
Line 21:// calling the setUp() method using object ob
Line 22:// calling the tearDown() method using object ob
Line 23:// calling the testX() method using object ob
Line 24:// calling the testY() method using object ob
Line 25:// End of main()
Line 26:// End of TestMe class
Program:
public class TestMe{
public TestMe(){
System.out.print("a");
}
public void setUp(){
System.out.print("b");
}
public void tearDown(){
System.out.print("c");
}
//@Test
public void testX(){
System.out.print("x");
}
//@Test
public void testY(){
System.out.print("y");
}
public static void main(String args[]) {
TestMe ob=new TestMe();
ob.setUp();
ob.tearDown();
ob.testX();
ob.testY();
}
}
Output: