测试类如下:
import junit.framework.TestCase; public class TestThatWeGetHelloWorldPrompt extends TestCase { public TestThatWeGetHelloWorldPrompt( String name) { super(name); } public void testSay() { HelloWorld hi = new HelloWorld(); assertEquals("Hello World!", hi.say()); //这句是关键,表示你的结果和实际需要的预期结果进行的对比 } public static void main(String[] args) { junit.textui.TestRunner.run( TestThatWeGetHelloWorldPrompt.class); } } |
测试案例写好后,点击运行为Junit即可~
如果看到的是绿色的条,说明测试通过,如果是红色的条,说明测试不通过,这时候需要查看错误的原因