我是Junit的新手。我有一个关于Java如何运行Junit类的问题。我有这样的代码
public class TestJunit1 {
String message = "Srinivas";
MessageUtil messageutil = new MessageUtil(message);
@Test
public void testPrintMessage() {
System.out.println("Inside testPrintMessage");
assertEquals(message, messageutil.printMessage());
}
}
public class TestJUnit5 extends TestCase {
protected double fValue1;
protected double fValue2;
@Before
public void setUp() throws Exception {
fValue1 = 2.0;
fValue2 = 3.0;
}
@Test
public void testAdding() {
System.out.println("No of test cases =" + this.countTestCases());
String name = this.getName();
System.out.println("Test Case name is: "+name);
this.setName("methodNewAdd");
String newName = this.getName();
System.out.println("New name of the test case is:"+newName);
System.out.println(this.getClass());
}
@After
public void tearDown() throws Exception {
}
public class TestSuiteDemo {
public static void main(String[] args) {
TestSuite ts = new TestSuite(TestJunit1.class, TestJunit2.class, TestJUnit5.class);
TestResult tr = new TestResult();
ts.run(tr);
System.out.println("Number of test cases is:"+tr.runCount());
}
}
当我在eclipse中运行TestSuiteDemo作为Java应用程序时,它从TestJUnit5而不是TestJunit1的println语句生成输出。 有人可以解释为什么会这样吗?
此致 Srinivas