深圳遞四方科技JAVA筆試:JUnit之TestCase和TestSuite
有如下單元測試類,請回答當用TestRunner執行該單元測試類時,輸出結果是()
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestSimpleBean2 extends TestCase {
public TestSimpleBean2(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
System.out.println("setUp" );
}
protected void tearDown() throws Exception {
super.tearDown();
System.out.println("tearDown");
}
public void testMethod() {
System.out.println("testMethod");
}
public void foo() {
System.out.println("foo");
}
public static TestSuite suite () {
TestSuite suite = new TestSuite();
suite.addTest(new TestSimpleBean2("foo"));
return suite;
}
}
A. setUp
B. tearDown
C. testMethod
D. foo
面試公司給出的正確答案是:C
請大家自行決斷,我不認為正確答案是C,我親測輸出如下,有沒有大牛回答一下
setUp
foo
tearDown